PP 1902
PP 1902
1|Page
February 19, 2025 [ Python programming ]
Assignment NO: 02
INDEX
S.No Program Date
06 Write a program to create, append and remove list 19/02/2025
in python.
07 Write a program to demonstrate working with tuples 19/02/2025
in python.
08 Write a program to demonstrate working with 19/02/2025
dictionaries in python
09 Write a program to check whether a number is even 19/02/2025
or odd using if condition.
10 Write a program to demonstrate for loop 19/02/2025
11 Write a program to demonstrate while loop 19/02/2025
Source Code :
print(fruits)
fruits.append("Pineapple")
print(fruits)
fruits.insert(1,"Mango")
print(fruits)
fruits.remove("Orange")
print(fruits)
del fruits[1]
print(fruits)
3|Page
February 19, 2025 [ Python programming ]
if "apple" in fruits:
Source code:
# Creating a dictionary
fruits = {
"name": "apple",
4|Page
February 19, 2025 [ Python programming ]
"color": "red",
"id": "1"
print(fruits)
fruits["taste"] = "sweet"
print(fruits)
fruits["taste"] = "yummy"
print(fruits)
# To remove items
#Use pop ()
fruits.pop("taste")
print(fruits)
myfruit= fruits.copy()
5|Page
February 19, 2025 [ Python programming ]
print(myfruit)
#print(x)
if x%2== 0:
print("{} is Even".format(x))
else:
print("{} is Odd".format(x))
6|Page
February 19, 2025 [ Python programming ]
x = [0,1,2,3,4,5,6,7,8,9]
y = list(range(10))
for i in range(1,11):
print(i)
fruits = {"apple",'banana','Orange'}
for i in fruits:
print(i)
for i in range(1,11):
print(str(5).rjust(2),"*",str(i).rjust(2),"=",str(5*i).rjust(2))
7|Page
February 19, 2025 [ Python programming ]
Source Code
a,b = 0,1
8|Page
February 19, 2025 [ Python programming ]
print (b,a)
a,b = b,a+b
Source Code
def check_prime(x):
token = True
for i in range(2,x):
9|Page
February 19, 2025 [ Python programming ]
return False
if token:
print(' {} is prime'.format(x))
return True
for i in range(50,60):
check_prime(i)
10 | P a g e