Practical File For Class IX (For Term 2) 2023-24
Practical File For Class IX (For Term 2) 2023-24
if save == sum:
print("Number is an Armstrong Number")
else:
print("Number is not an Armstrong Number")
20. Create a program in Python to find sum of all even digits and odd digits of a number separately.
# Program to find the sum of odd and even digits of a number
n = int(input("Enter a number : "))
save = n
sumeven = 0
sumodd = 0
while n > 0:
r = n % 10
if r % 2 == 0:
sumeven= sumeven + r
else:
sumodd = sumodd + r
n = n//10
print("Sum Of odd digits of a number ",save , " = ",sumodd)
print("Sum Of even digits of a number ",save , " = ",sumeven)
21. Create a program in Python to find reverse of a number.
# Program to find the reverse number of a number
n = int(input("Enter a number : "))
revno = 0
save = n
while n>0:
r = n % 10
revno = revno*10 + r
n = n//10
print("Reverse of a number ",save , " = ",revno)
22. Create a program in Python to create a list ‘Marks’ containing 6 marks of six subjects out of 40.
Now calculate the percent scored by student.
23. Create a program in Python to create a list, asking user to input admission number, name, gender and
house
Source Code:
admno = int(input("Enter your admission number : "))
name = input("Enter your name : ")
gender = input("Enter your gender : ")
house = input("Enter your house : ")
my_record = [] # blank list
my_record.append(admno)
my_record.append(name)
my_record.append(gender)
my_record.append(house)
print("My details : ", my_record)
Output:
Enter your admission number : 2356
Enter your name : Akshita
Enter your gender : Female
Enter your house : Gandhi
My details : [2356, 'Akshita', 'Female', 'Gandhi']
24. Create a program in Python to create a list, containing three colours (“Red”, “Green” and “Blue”).
Now perform the following task on the list created above.
Add colour “Cyan” in the list (at the end).
Add colour “Orange” in the list at third position.
Add colour “White” in the list at the first place.
Now replace colour “Orange” with colour “Saffron”.
Display the number of colours in the list.
Note: after every task print the content of the list.
Source Code:
Colours = ["Red" , "Green", "Blue"]
print("Original list : ", Colours)
Colours.append("Cyan") #Colours.insert(len(Colours),”Cyan)
print(Colours)
Colours.insert(2,"Orange")
print(Colours)
Colours.insert(0,"White")
print(Colours)
Colours[3] = "Saffron"
print(Colours)
print("Number of colours in the list are : ", len(Colours))
Output:
Original list : ['Red', 'Green', 'Blue']
['Red', 'Green', 'Blue', 'Cyan']
['Red', 'Green', 'Orange', 'Blue', 'Cyan']
['White', 'Red', 'Green', 'Orange', 'Blue', 'Cyan']
['White', 'Red', 'Green', 'Saffron', 'Blue', 'Cyan']
Number of colours in the list are : 6
Output:
Original list : ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
['Monday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
['Monday', 'Thursday', 'Friday', 'Saturday']
['Monday', 'Thursday', 'Saturday']
Number of days in list : 3
Source Code:
L = [12,34,38,56,51,82,29,89,33,99]
print("Original list : ", L)