0% found this document useful (0 votes)
25 views5 pages

Practical File For Class IX (For Term 2) 2023-24

The document contains a series of Python programming exercises designed for Class IX students. Each exercise includes a specific task, such as calculating the sum of digits, checking for Armstrong numbers, manipulating lists, and performing various operations on them. The document provides source code examples and expected outputs for each task.

Uploaded by

sudhakumar3542
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views5 pages

Practical File For Class IX (For Term 2) 2023-24

The document contains a series of Python programming exercises designed for Class IX students. Each exercise includes a specific task, such as calculating the sum of digits, checking for Armstrong numbers, manipulating lists, and performing various operations on them. The document provides source code examples and expected outputs for each task.

Uploaded by

sudhakumar3542
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

PRACTICAL FILE- ARTIFICIAL INTELLIGENT[CLASS – IX]

18. Create a program in Python to find sum of a digits of a number.


# Program to find the sum of digits of a number
n = int(input("Enter a number : "))
save = n
sum = 0
while n>0:
r = n % 10
sum = sum +r
n = n//10
print("Sum Of digits of a number ",save , " = ",sum)

19. Create a program in Python to find, if a number is an Armstrong number or not.


# Program to find if a number is an Armstrong number or not
# 1, 153, 370, 371 , 407
import math
n = int(input("Enter a number : "))
sum = 0
save = n
while n>0:
r = n % 10
sum = sum + math.pow(r,3) #sum = sum +r*r*r
n = n//10

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.

# Program to calculate percent


Marks = [35.5, 36, 33, 34.5, 38, 39]
Total = Marks[0] + Marks[1] + Marks[2] + Marks[3] + Marks[4] + Marks[5]
Percent = Total/240 *100
print("Total marks Obtained = ", Total)
print("Percent Obtained = ", Percent)
Output

Total marks Obtained = 216


Percent Obtained = 90

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

25. Create a program in Python to create a list, containing name of weekdays.


Now perform the following task on the list created above.
 Deleteday “Sunday” from the list using pop() method.
 Delete day “Tuesday” from the list using pop() method.
 Delete day “Wednesday” from the list using remove() method.
 Delete day “Friday” from the list using del statement.
 Display the number of days in the list.
 Now delete complete list permanently.
Note: after every task print the content of the list.
Source Code:
Weekdays = ["Monday" , "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
print("Original list : ", Weekdays)

Weekdays.pop() # Bydefault pop() deletes last element.


print(Weekdays)
Weekdays.pop(1)
print(Weekdays)
Weekdays.remove("Wednesday")
print(Weekdays)
del Weekdays[2]
print(Weekdays)
print("Number of days in list : ",len(Weekdays))
del Weekdays

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

26. Create a program in Python to create a list, containing 10 numbers (12,34,38,56,51,82,29,89,33,99).


Now perform the following task on the list created above.
 Display slice [56,51,82,29,89] from the list using forward/positive index.
 Display slice [82,29,89,33] from the list using backward/negative index.
 Display numbers at the odd indexes.
 Display the numbers at the even indexes.
 Display list elements in reverse order.
 Display slice [12,56,29,99] from the list

Source Code:
L = [12,34,38,56,51,82,29,89,33,99]
print("Original list : ", L)

#Display slice [56,51,82,29,89] from the list using forward/positive index.


print(L[3:8])
#Display slice [82,29,89,33] from the list using backward/negative index.
print(L[-5:-1])
#Display numbers at the odd indexes.
print(L[1: :2])
#Display the numbers at the even indexes.
print(L[0: :2])
#Display list elements in reverse order.
print(L[: : -1])
#Display slice [12,56,29,99] from the list
print(L[0: : 3])
Output:
Original list : [12, 34, 38, 56, 51, 82, 29, 89, 33, 99]
[56, 51, 82, 29, 89]
[82, 29, 89, 33]
[34, 56, 82, 89, 99]
[12, 38, 51, 29, 33]
[99, 33, 89, 29, 82, 51, 56, 38, 34, 12]
[12, 56, 29, 99]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy