Page 254 - COPA Vol II of II - TP - Bengali
P. 254
টযাস্ক 5 : আউিপুি ডেন্যাে
# Python program showing use of format() method # using format() method and referring a position of the
using format() method object
print(‘Welcome {} to “{}!”’.format(‘NIMI’, ‘NIMI’)) print(f”{‘NImi’} and {‘Portal’}”)
# using format() method and referring a position of the Output:
object Welcome NIMI to “NIMI!”
print(‘{0} and {1}’.format(‘NIMI’, ‘Portal’)) NIMI and Portal
print(‘{1} and {0}’.format(‘NIMI’, ‘Portal’)) Portal and NIMI
# the above formatting can also be done by using Welcome nimi for “NIMI!”
f-Strings Although, this features work only with python NImi and Portal
print(f”Welcome {‘nimi’} for \”{‘NIMI’}!\””)
টযাস্ক 6 : আউিপুি ডেন্যালেি অপালিিিগুডল
# Python program showing how to use print(“Octal: %7.3o” % (25))
# string modulo operator(%) to print # print exponential value
# fancier output print(“Exponential: %10.3E” % (356.08977))
# print integer and float value Output:
print(“Integer : %2d, Float : %5.2f” % (1, 2.0)) Integer : 1, Float : 2.00
# print integer value Integer: 240, Boys : 120
print(“Integer: %3d, Boys : %2d” % (240, 120)) Octal: 031
# print octal value Exponential: 3.561E+02
240 IT & ITES - COPA - (NSQF প্ললভল- 2022) - অনুশীলনী 1.39.04