Page 248 - COPA VOL II of II - TP -Punjabi
P. 248
print(“Print String in default order: “) print(String1)
print(String1) Output:
# Positional Formatting Print String in default order:
String1 = “{1} {0} {2}”.format(‘Welcome’, ‘to’, ‘NIMI’) Welcome to NIMI
print(“\nPrint String in Positional order: “) Print String in Positional order:
print(String1) to Welcome NIMI
# Keyword Formatting Print String in order of Keywords:
String1 = “{l} {f} {g}”.format(g=’NIMI’, f=’to’, l=’Welcome’) Welcome to NIMI
print(“\nPrint String in order of Keywords: “)
TASK 3: Date operations
Example1: print(x.strftime(“%A”))
import datetime Output:
x = datetime.datetime.now() 2022
print(x) Saturday
Output: Example3:
2022-07-09 16:05:52.588848 import datetime
Example 2: x = datetime.datetime(2020, 5, 17)
import datetime print(x)
x = datetime.datetime.now() Output:
print(x.year) 2020-05-17 00:00:00
TASK 4: Input and output operations
Example for Input: Welcome to Python Programming
x = int (input(“Enter Number 1: “)) 11
y = int (input(“Enter Number 2: “)) The sum = 11
print (“The sum = “, x+y) The sum of 5 and 6 is 11
Output: Example for Input and Output:
Enter Number 1: 5 # Python program showing how to multiple input and
output using split
Enter Number 2: 10
# taking two inputs at a time
The sum = 15
Example for Output: x, y = input(“Enter two values: “).split()
print(“Number of boys: “, x)
print (“Welcome to Python Programming”)
print(“Number of girls: “, y)
x = 5
y = 6 print()
# taking three inputs at a time
z = x + y
x, y, z = input(“Enter three values: “).split()
print (z)
print (“The sum = “, z) print(“Total number of students: “, x)
print(“Number of boys is : “, y)
print (“The sum of “, x, “ and “, y, “ is “, z)
print(“Number of girls is : “, z)
Output:
print()
234 IT & ITES - COPA - (NSQF ਸੋਧੇ - 2022) - ਅਿਭਆਸ 1.39.04