0% found this document useful (0 votes)
160 views

Grade IX-Program List

Uploaded by

ushabuddha05
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views

Grade IX-Program List

Uploaded by

ushabuddha05
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Grade IX - Annual Practical Exam Program List

L1. Create a list in Python of children selected for a science quiz with the following names:

Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, and Kartik.

Perform the following tasks on the list in sequence:

a. Print the whole list.

b. Delete the name "Vikram" from the list.

c. Add the name "Jay" at the end.

d. Remove the item that is at the second position.

Solution:
# Create a list of children selected for a science quiz
children = ["Arjun", "Sonakshi", "Vikram", "Sandhya", "Sonal", "Isha", "Kartik"]

# a. Print the whole list


print("Initial list:")
print(children)

# b. Delete the name "Vikram" from the list


children.remove("Vikram")
print("\nList after removing 'Vikram':")
print(children)

# c. Add the name "Jay" at the end


children.append("Jay")
print("\nList after adding 'Jay':")
print(children)

# d. Remove the item that is at the second position


children.pop(1)
print("\nList after removing the item at the second position:")
print(children)

Output:
Initial list:
['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
List after removing 'Vikram':
['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
List after adding 'Jay':
['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jay']
List after removing the item at the second position:
['Arjun', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jay']

L2. Create a list num = [23,12,5,9,65,44]


a. Print the length of the list.

b. Print the elements from second to fourth position using positive indexing.

c. Print the elements from position 3 to position 5 using negative indexing.

Solution:
# Create a list of numbers
num = [23, 12, 5, 9, 65, 44]

# a. Print the length of the list


print("Length of the list:", len(num))

# b. Print the elements from second to fourth position using positive indexing
print("\nElements from second to fourth position (positive indexing):")
print(num[1:4])

# c. Print the elements from position 3 to position 5 using negative indexing


print("\nElements from position 3 to position 5 (negative indexing):")
print(num[-4:-1])

Output:
Length of the list: 6
Elements from second to fourth position (positive indexing):
[12, 5, 9]
Elements from position 3 to position 5 (negative indexing):
[5, 9, 65]

L3. Write a Python program to find the sum of all numbers stored in a list.

Solution:
# Create a list of numbers
numbers = [12, 45, 7, 23, 56, 89, 34]

# Use the built-in sum() function to calculate the sum


total_sum = sum(numbers)

# Print the sum


print("The sum of the numbers in the list is:", total_sum)

Output:
The sum of the numbers in the list is: 266

L4. Create a list of the first 10 even numbers, add 1 to each list item, and print the final
list.

Solution:
# Create a list of the first 10 even numbers
even_numbers = list(range(0, 20, 2))
# Print the original list
print("Original List:")
print(even_numbers)

# Add 1 to each list item


even_numbers = [num + 1 for num in even_numbers]

# Print the final list


print("\nFinal List:")
print(even_numbers)

Output:
Original List:
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
Final List:
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]

L5. Create a list List_1 = [10,20,30,40]. Add the elements [14,15,12] using the extend
function. Now, sort the final list in ascending order and print it.

Solution:
# Create a list
list_1 = [10, 20, 30, 40]

# Print the original list


print("Original List:")
print(list_1)

# Add elements to the list using the extend function


list_1.extend([14, 15, 12])

# Print the list after adding elements


print("\nList after adding elements:")
print(list_1)

# Sort the list in ascending order


list_1.sort()

# Print the sorted list


print("\nSorted List:")
print(list_1)

Output:
Original List:
[10, 20, 30, 40]
List after adding elements:
[10, 20, 30, 40, 14, 15, 12]
Sorted List:
[10, 12, 14, 15, 20, 30, 40]
L6. Create a list sub = [‘English’, ‘Hindi’, ‘French’, ‘Math’, ‘Science’].

a. Delete the name ‘Hindi’ from the list.

b. Print the whole list after deleting the above name.

d. Add the names ‘AI’ and ‘Science’ at the end of the list using extend() function and
display the final list.

Solution:
# Create a list of subjects
sub = ['English', 'Hindi', 'French', 'Math', 'Science']

# a. Delete the name 'Hindi' from the list


sub.remove('Hindi')

# b. Print the whole list after deleting the above name


print("List after deleting 'Hindi':")
print(sub)

# Add the names 'AI' and 'Python' at the end of the list using extend() function
sub.extend(['AI', 'Python'])

# Display the final list


print("\nFinal List:")
print(sub)

Output:
List after deleting 'Hindi':
['English', 'French', 'Math', 'Science']

Final List:
['English', 'French', 'Math', 'Science', 'AI', 'Python']

L7. Create a list numbers = [23, 56,12,55,60,23].

a. Print the number ‘12’ using negative indexing.

b. Print the smallest and largest number from the above list.

d. Print the occurrence of number ‘23’ in the above list.

Solution:
# Create a list of numbers
numbers = [23, 56, 12, 55, 60, 23]

# a. Print the number '12' using negative indexing


print("Number '12' using negative indexing:")
print(numbers[-5])

# b. Print the smallest and largest number from the above list
print("\nSmallest number:", min(numbers))
print("Largest number:", max(numbers))

# d. Print the occurrence of number '23' in the above list


print("\nOccurrence of number '23':", numbers.count(23))

Output:
Number '12' using negative indexing:
12
Smallest number: 12
Largest number: 60
Occurrence of number '23': 2

Q2.

F1. Write a program to find numbers that are divisible by 7 and multiples of 5 between
1200 and 2200.

Solution:
start = 1200
end = 2200

numbers = []

for i in range(start, end+1):


if i % 7 == 0 and i % 5 == 0:
numbers.append(i)

print("Numbers between " + str(start) + " and " + str(end) + " that are divisible by 7 and
multiples of 5:")
print(numbers)

Output:

Numbers between 1200 and 2200 that are divisible by 7 and multiples of 5:
[1225, 1260, 1295, 1330, 1365, 1400, 1435, 1470, 1505, 1540, 1575, 1610, 1645, 1680,
1715, 1750, 1785, 1820, 1855, 1890, 1925, 1960, 1995, 2030, 2065, 2100, 2135, 2170]

F2. Write a program to input the monthly income of an employee between 40 and 60
years old and calculate the annual income tax on the basis of the following:
Tax Slab Rates

3 lakhs NIL

3 lakhs to 5 lakhs 5.00%

5 lakhs to 10 lakhs 20.00%

10 lakhs 30.00%

Solution:
# Input monthly income and age
monthly_income = float(input("Enter your monthly income: "))
age = int(input("Enter your age: "))

# Check if age is between 40 and 60


if 40 <= age <= 60:
# Calculate annual income
annual_income = monthly_income * 12

# Calculate income tax


if annual_income <= 300000:
tax = 0
elif 300000 < annual_income <= 500000:
tax = (annual_income - 300000) * 0.05
elif 500000 < annual_income <= 1000000:
tax = (200000 * 0.05) + ((annual_income - 500000) * 0.20)
else:
tax = (200000 * 0.05) + (500000 * 0.20) + ((annual_income - 1000000) * 0.30)

# Print annual income and income tax


print("Annual Income: ", annual_income)
print("Income Tax: ", tax)
else:
print("Age is not between 40 and 60.")

Output:
Enter your monthly income: 600000
Enter your age: 56
Annual Income: 7200000.0
Income Tax: 1970000.0

F3. Write a program to print the sum of even numbers from 1 to 15 using for loop.

Solution:
sum_even = 0
for i in range(1, 16):
if i % 2 == 0:
sum_even += i
print("The sum of even numbers from 1 to 15 is:", sum_even)
Output:
The sum of even numbers from 1 to 15 is: 56
F4. Write a program that determines if the user can ride a roller coaster or not.

(Hint: age should be greater than or equal to 18 and height at least 1.5 meters tall).

Solution:
print("Roller Coaster Ride Eligibility Checker")

age = int(input("Enter your age: "))


height = float(input("Enter your height in meters: "))

if age >= 18 and height >= 1.5:


print("Congratulations! You are eligible to ride the roller coaster.")
else:
print("Sorry, you are not eligible to ride the roller coaster.")
if age < 18:
print("You are too young to ride the roller coaster. You must be at least 18 years old.")
if height < 1.5:
print("You are too short to ride the roller coaster. You must be at least 1.5 meters
tall.")

Output:
Roller Coaster Ride Eligibility Checker
Enter your age: 12
Enter your height in meters: 1.5
Sorry, you are not eligible to ride the roller coaster.
You are too young to ride the roller coaster. You must be at least 18 years old.

F5. Write a program to generate the following pattern:

11111
2222
333
44
5

Solution:
# outer loop to control the number of rows
for i in range(1, 6):
# inner loop to control the number of repetitions
for j in range(6 - i):
print(i, end="")
print()

Output:

11111
2222
333
44
5

F6. Write a Python program using a while loop to print even numbers from 1 to 20.

Solution:
i=1
# loop through numbers 1 to 20
while i <= 20:
if i % 2 == 0:
print(i)
#increment i by 1 after each iteration
i += 1

Output:
2
4
6
8
10
12
14
16
18
20

F7. A sports coach has conducted a fitness test of 200 marks. He awarded ‘Gold’ grade to
all the students who scored more than 180 marks, 'Silver' grade to the students who
scored between 160 and 180 marks, 'Bronze' grade to all the students who scored
between 140 to 160 marks, and 'Fail' grade to all the students who scored below 140
marks. Write a Python code that shows his grading strategy.

Solution:
marks = float(input("Enter the student's marks (out of 200): "))

if marks > 180:


print("Student's Marks: ", marks)
print("Grade: Gold")
elif 160 <= marks <= 180:
print("Student's Marks: ", marks)
print("Grade: Silver")
elif 140 <= marks <= 160:
print("Student's Marks: ", marks)
print("Grade: Bronze")
else:
print("Student's Marks: ", marks)
print("Grade: Fail")
Output:
Enter the student's marks (out of 200): 189
Student's Marks: 189.0
Grade: Gold

B1. Write a program to check whether the entered number is positive and even, positive
and odd, negative and even, or negative and odd.

Solution:
num = int(input("Enter a number: "))

if num > 0:
if num % 2 == 0:
print(num, "is a positive even number.")
else:
print(num, "is a positive odd number.")
elif num < 0:
if num % 2 == 0:
print(num, "is a negative even number.")
else:
print(num, "is a negative odd number.")
else:
print("You entered zero. Zero is neither positive nor negative, and it is even.")

Output:

Enter a number: -8
-8 is a negative even number.

B2. Write a program to find the sum of numbers from 1 to 10 using the range(n) function.

Solution:
sum_of_numbers = 0
for i in range(1, 11):
sum_of_numbers += i
print("The sum of numbers from 1 to 10 is:", sum_of_numbers)

Output:
The sum of numbers from 1 to 10 is: 55

B3. Write a program calculate the surface area and volume of a cuboid.

Solution:
# Get the dimensions of the cuboid from the user
length = float(input("Enter the length of the cuboid: "))
width = float(input("Enter the width of the cuboid: "))
height = float(input("Enter the height of the cuboid: "))
# Calculate the surface area of the cuboid
surface_area = 2 * (length * width + width * height + length * height)

# Calculate the volume of the cuboid


volume = length * width * height

# Print the results


print("Surface Area of the Cuboid: ", surface_area)
print("Volume of the Cuboid: ", volume)

Output:
Enter the length of the cuboid: 7.5
Enter the width of the cuboid: 4
Enter the height of the cuboid: 2
Surface Area of the Cuboid: 106.0
Volume of the Cuboid: 60.0

B4. Write a program check whether the applicant is eligible to vote in the election or not.

Solution:
name = input("Enter your name: ")
age = int(input("Enter your age: "))
citizenship = input("Are you an Indian citizen? (yes/no): ")

if age >= 18 and citizenship.lower() == "yes":


print(name, "is eligible to vote in the election.")
else:
if age < 18:
print(name, "is not eligible to vote in the election because you are underage.")
elif citizenship.lower() != "yes":
print(name, "is not eligible to vote in the election because you are not an Indian
citizen.")

Output:
Enter your name: Anila
Enter your age: 22
Are you an Indian citizen? (yes/no): YES
Anila is eligible to vote in the election.

You might also like