Grade 9 AI Python Programs (1)
Grade 9 AI Python Programs (1)
print("Name:", name)
print("Father's Name:", father_name)
print("Class:", class_name)
print("School Name:", school_name)
1
Question: Write a program to print the following patterns using multiple print
commands
print("* *****")
print("** ****")
print("*** ***")
print("**** **")
print("***** *")
2
Question : Write a program to find Square of Number
num = float(input("Enter a number: "))
square = num ** 2
print("Square of", num, "is", square)
==================================================================
3
Question: Write a program to find sum of any two numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
sum = num1 + num2
print("Sum of", num1, "and", num2, "is", sum)
==================================================================
4
Question : Write a program to convert kilometres to meters
5
Question : Write a program to print table of any input number
6
Question : Write a program calculate simple interest
7
Question : Write a program calculate area and perimeter of rectangle
8
Question : Write a program calculate area of triangle
9
Question : Write a program calculate average marks
10
Question : Write a program calculate discounted amount
11
Question: Write a program calculate surface area and volume of cuboid
# Function to calculate surface area and volume of a cuboid
def calculate_cuboid_surface_area_and_volume(length, width, height):
# Surface area formula: 2 * (lw + lh + wh)
surface_area = 2 * (length * width + length * height + width * height)
# Volume formula: l * w * h
volume = length * width * height
12
Question : Write a program Create a list in Python of children selected for science quiz
with following namesArjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik Perform
the following tasks on the list in sequence- ○ Print the whole list ○ Delete the name
“Vikram” from the list ○ Add the name “Jay” at the end ○ Remove the item which is at
the second position.
# Step 1: Create a list of children selected for the science quiz
children = ["Arjun", "Sonakshi", "Vikram", "Sandhya", "Sonal", "Isha", "Kartik"]
13
Question : Write a program Create a list num=[23,12,5,9,65,44]
○ print the length of the list
○ print the elements from second to fourth position using positive indexing
○ print the elements from position third to fifth using negative indexing
# Print the elements from the second to fourth position using positive indexing
print("Elements from second to fourth position (positive indexing):", num[1:4])
# Print the elements from the third to fifth position using negative indexing
print("Elements from third to fifth position (negative indexing):", num[-4:-1])
==================================================================
14
Question :Write a program to Create a list of first 10 even numbers, add 1 to each list
item and print the final list.
15
Question:Write a program to Create a list List_1=[10,20,30,40]. Add the elements
[14,15,12] using extend function. Now sort the final list in ascending order and print it.
# Create a list List_1
List_1 = [10, 20, 30, 40]
print("Original list:", List_1)
16
Question: Write a program to check if a person can vote
17
Question: Write a program To check the grade of a student
# Function to determine the grade
def check_grade(marks):
if marks >= 90:
return "A+"
elif marks >= 80:
return "A"
elif marks >= 70:
return "B"
elif marks >= 60:
return "C"
elif marks >= 50:
return "D"
else:
return "F"
18
Question: Write a program Input a number and check if the number is positive,
negative or zero and display an appropriate message
# Input a number from the user
try:
number = float(input("Enter a number: "))
=================================================================
19
Question: Write a program To print first 10 natural numbers
# Print the first 10 natural numbers
print("The first 10 natural numbers are:")
for number in range(1, 11):
print(number)
=================================================================
20
Question: Write a program to print first 10 even numbers
# Print the first 10 even numbers
print("The first 10 even numbers are:")
for number in range(2, 21, 2):
print(number)
==================================================================
21
Question: Write a program to print odd numbers from 1 to n
# Input the value of n
try:
n = int(input("Enter the value of n: "))
if n > 0:
print(f"Odd numbers from 1 to {n} are:")
for number in range(1, n + 1, 2):
print(number)
else:
print("Please enter a positive integer.")
except ValueError:
print("Invalid input. Please enter an integer.")
==================================================================
22
Question: Write a program to print sum of first 10 natural numbers
# Calculate the sum of the first 10 natural numbers
sum_of_numbers = sum(range(1, 11))
23
Question: Write a program to find the sum of all numbers stored in a list
# List of numbers
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
24