Project Ai
Project Ai
PYTHON PROGRAMMING
FOR ICSE 2026 EXAMINATION
if number % 2 == 0:
#this is to check wheteher a number is divisible by 0 or not
print("The number is even.")
#if it is divisible by 2 then it will print the number as even
else:
#if it is not divisible by 2 then it will print the number as odd
print("The number is odd.")
VDT:
variable datatype purpose
number Int or integer Stores the number entered by
the user.
Algorithm:
1. Input a number from the user.
2. Check if the number is divisible by 2 without any remainder.
3. If yes, print "The number is even", otherwise print "The number is odd".
Output:
For example, if the user inputs 7, the output will be "The number is odd."
This program effectively determines whether a given number is even or odd and provides the
corresponding message.
PROGRAM 2
Write a script to input a number. If the number is even, print its square, otherwise print
its cube.
number = int(input("Enter a number: "))
if number % 2 == 0:
#this is to check whether the number is divisible by 2 or not
print("Square of", number, "is", number**2)
#if it is divisible by 2 then print the sqaure of the number
else:
#and if it is not divisible by 2 then print the cube of the number
print("Cube of", number, "is", number**3)
VDT:
variable datatype purpose
number Int or integer Stores the number entered by
the user.
Algorithm:
1. Input a number from the user.
2. Check if the number is divisible by 2 without any remainder.
3. If yes, print the square of the number, otherwise print the cube of the number.
Output:
For instance, if the user inputs 5, the output will be "Cube of 5 is 125."
This program provides the square of an even number and the cube of an odd number, based on
user input.
PROGRAM 3
Write a script which inputs two numbers from the user and checks if the first number is
divisible by the second or not. The script should then display an appropriate message.
if num2 == 0:
print("Cannot divide by zero.")
#as no number can be divided by zero so this print line will show that the 2nd number cannot
divide the 1st number(as 2nd number is 0)
elif num1 % num2 == 0:
print(num1, "is divisible by", num2)
#if number 1 is divisible by the 2nd number then it will print the above statement.
else:
print(num1, "is not divisible by", num2)
#and if the 1st number is not divisible by the 2nd number then it will the the above statement.
VDT:
variable datatype purpose
num1 Int or integer Stores the number entered by
the user.
num2 Int or integer Stores the number entered by
the user.
ALGORITHM:
1. Prompt the user to enter the first number.
2. Read the input and convert it to an integer.
3. Prompt the user to enter the second number.
4. Read the input and convert it to an integer.
5. Check if the second number is zero:
If it is zero, print a message indicating that division by zero is not allowed.
6. Otherwise, check if the first number is divisible by the second number:
If it is divisible, print a message indicating that the first number is divisible by the second
number.
If it is not divisible, print a message indicating that the first number is not divisible by the second
number.
OUTPUT:
Case 1: Divisible
PROGRAM:
# Input the number of students
num_students = int(input("Enter the number of students in the class: "))
VDT:
ALGORITHM:
1. Prompt the user to enter the number of students in the class.
2. Read the input and convert it to an integer.
3. Check if the input number is negative.
If it is negative, convert the number to its positive value using the abs() function.
4. Print the non-negative number of students.
OUTPUT:
Case 1: Positive Input
PROGRAM 5:
Write a script to input 10 numbers and then display the smallest number entered. If the
smallest number is an integer, then find the sum of its digits, otherwise display the message
“smallest number is not an integer”.
VDT:
VARIABLE DATA TYPE PURPOSE
numbers List[float] To store the 10 numbers
entered by the user
i int Loop counter to iterate
through 10 numbers input
number float Temporary variable to store
each number entered by the
user
smallest_number float To store the smallest number
from the list of numbers
integer_part int To store the integer part of the
smallest number if it is an
integer
digit_sum int To store the sum of the digits
of the smallest integer
ALGORITHM:
Use the min() function to find the smallest number in the list.
Check if the smallest number is an integer. If it is, calculate the sum of its digits and print
the result. If it is not, print a message indicating that the smallest number is not an
integer.
OUTPUT:
PROGRAM 6:
Write a script to input principal, time and calculate simple interest. If time is more than 10
years, calculate simple interest at the rate of 8% p.a., otherwise calculate it at the rate of
12% p.a.
VDT:
Variable Data Type Purpose
ALGORITHM:
Prompt the user to input the principal amount and the number of years.
If time is 10 or less:
PROGRAM 7:
Write a script to input three numbers and find whether they form the three sides of a
triangle.
# Input three numbers from the user representing the sides of a triangle
a = float(input("Enter the first side length: "))
b = float(input("Enter the second side length: "))
c = float(input("Enter the third side length: "))
# Check if the sum of any two sides is greater than the third side
if a + b > c and a + c > b and b + c > a:
# If all conditions are met, the sides can form a triangle
print("The numbers can form a triangle.")
else:
# If any condition is not met, the sides cannot form a triangle
print("The numbers cannot form a triangle.")
VDT:
variable Data type Purpose
a float To store the length of the first
side of the triangle.
b float To store the length of the
second side of the triangle.
c float To store the length of the third
side of the triangle.
ALGORITHM:
Print "The numbers can form a triangle" if all conditions are met.
Otherwise, print "The numbers cannot form a triangle."
OUTPUT:
PROGRAM 8:
Write a script to input the coefficients (a,b,c) of a quadratic equation ax^2+bx+c=0, and
find the nature of its roots (Real and equal roots, Real and unequal roots, or Complex
roots).
VDT:
Variable Data Type Purpose
a float To store the coefficient of x^2
in the quadratic equation.
b float To store the coefficient of xxx
in the quadratic equation.
c float To store the constant term in
the quadratic equation.
discriminant float To calculate and store the
value of b2−4acb^2 -
4acb2−4ac which determines
the nature of the roots.
ALGORITHM:
Input Coefficients:
Prompts the user to enter the coefficients aaa, bbb, and ccc of the quadratic equation.
Calculate Discriminant:
OUTPUT:
Example input: a = 1, b = 2, c = 1
Output:
o The roots are real and equal.
Complex Roots:
Example input: a = 1, b = 2, c = 5
Output:
o The roots are complex.
EXTRA INFO:
The discriminant is the part of the quadratic formula underneath the square root symbol: b²-4ac.
The discriminant tells us whether there are two solutions, one solution, or no solutions.
PROGRAM 10:
Write a menu driven script to calculate the total surface area and volume of a cube,
cuboid, or sphere depending upon the user's choice.
# Value of pi
pi = 3.141592653589793
while True:
print("\nMenu:")
print("1. Cube")
print("2. Cuboid")
print("3. Sphere")
print("4. Exit")
if choice == '1':
side = float(input("Enter the side length of the cube: "))
surface_area = 6 * (side ** 2)
volume = side ** 3
print(f"Surface Area of the cube: {surface_area}")
print(f"Volume of the cube: {volume}")
else:
print("Invalid choice. Please enter a valid option.")
VDT:
Variable Data Type Purpose
pi Float To store the value of pi (π)
choice str To store the user's choice from
the menu
side Float To store the side length of the
cube
length Float Stores the length of the
cuboid.
width Float Stores the width of the cuboid.
height Float Stores the height of the
cuboid.
radius Float Stores the radius of the sphere.
surface_area Float Stores the calculated surface
area of the shape.
volume Float Stores the calculated volume
of the shape.
ALGORITHM:
Algorithm
1. Initialize Pi:
o Set pi to 3.141592653589793.
2. Display Menu and Get User Choice:
o Print the menu options.
o Read the user's choice.
3. Process User Choice:
o If Choice is 1 (Cube):
Prompt user for the side length.
Calculate the surface area and volume of the cube.
Display the surface area and volume.
o If Choice is 2 (Cuboid):
Prompt user for the length, width, and height.
Calculate the surface area and volume of the cuboid.
Display the surface area and volume.
o If Choice is 3 (Sphere):
Prompt user for the radius.
Calculate the surface area and volume of the sphere.
Display the surface area and volume.
o If Choice is 4 (Exit):
Print exiting message.
Break the loop and exit the program.
o If Choice is Invalid:
Display an error message and prompt user to enter a valid option.
OUTPUT:
Example 1: Cube
Input:
o Side length: 4
Output:
o Surface Area of the cube: 96.0
o Volume of the cube: 64.0
Example 2: Cuboid
Input:
o Length: 3
o Width: 4
o Height: 5
Output:
o Surface Area of the cuboid: 94.0
o Volume of the cuboid: 60.0
Example 3: Sphere
Input:
o Radius: 5
Output:
o Surface Area of the sphere: 314.1592653589793
o Volume of the sphere: 523.5987755982989
PROGRAM 11:
Write a script to input four numbers and find the largest of these without using built-
infunction max().
VDT:
ALGORITHM:
Input Numbers:
Prompt the user to enter four numbers and store them in num1, num2, num3, and num4.
Initialize Largest:
Set largest to num1.
Compare Numbers:
Compare largest with num2, num3, and num4 sequentially.
Update largest if any of these numbers are greater.
Output:Print the largest number.
OUTPUT:
Example 1:
Input:
num1: 5
num2: 8
num3: 3
num4: 7
Output:
The largest number is: 8
Example 2:
Input:
num1: -1
num2: -5
num3: -3
num4: -2
Output:
The largest number is: -1
PROGRAM 12:
12. Write a script which inputs three numbers from the user and displays these numbers in
ascending order.
VDT:
ALGORITM:
Input Numbers:
Compare num1 and num2. If num1 is greater than num2, swap them.
Compare num2 and num3. If num2 is greater than num3, swap them.
Compare num1 and num2 again. If num1 is greater than num2, swap them.
OUTPUT:
Example 1:
Input:
num1: 5
num2: 1
num3: 3
Output:
The numbers in ascending order are: 1.0, 3.0, 5.0
Example 2:
Input:
num1: -2
num2: 0
num3: -5
Output:
The numbers in ascending order are: -5.0, -2.0, 0.0
PROGRAM 13:
Write a program to find the sum of first n natural numbers, where n is to be input from
the user.
# Loop through the first n natural numbers and calculate the sum
for i in range(1, n + 1):
sum_of_natural_numbers += i
VDT:
Variable Data Type Purpose
n Int Stores the number of natural
numbers to sum
sum_of_natural_numbers Int Stores the accumulated sum of
the first n natural numbers
i int Loop counter to iterate
through numbers 1 to n
ALGORITM:
Input:
Prompt the user to enter a number nnn.
Read the input and store it in the variable n.
Initialize Sum:
Set sum_of_natural_numbers to 0.
Loop and Accumulate:
Use a for loop to iterate from 1 to nnn.
Add each number to sum_of_natural_numbers during each iteration.
Output:
Print the result showing the sum of the first nnn natural numbers.
OUTPUT:
Example 1:
Input:
n: 5
Output:
The sum of the first 5 natural numbers is: 15
Example 2:
Input:
n: 10
Output:The sum of the first 10 natural numbers is: 55
PROGRAM 14:
Write a program to input a number and check whether it is palindrome or not.
# Input the number from the user
number = input("Enter a number: ")
VDT:
Variable Data Type Purpose
ALGORITHM:
Input:
Check Palindrome:
Compare the number with its reverse (achieved using slicing number[::-1]).
Output:
OUTPUT:
Example 1:
Input:
number: 121
Output:
The number 121 is a palindrome.
Example 2:
Input:
number: 123
Output:
The number 123 is not a palindrome.
PROGRAM 15:
import math
while True:
# Display the menu
print("\nMenu:")
print("1. Cube")
print("2. Cuboid")
print("3. Sphere")
print("4. Exit")
if choice == 1:
# Calculate for Cube
side = float(input("Enter the side length of the cube: "))
surface_area = 6 * side ** 2
volume = side ** 3
print(f"Total surface area of the cube: {surface_area}")
print(f"Volume of the cube: {volume}")
elif choice == 2:
# Calculate for Cuboid
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: "))
surface_area = 2 * (length * width + width * height + height * length)
volume = length * width * height
print(f"Total surface area of the cuboid: {surface_area}")
print(f"Volume of the cuboid: {volume}")
elif choice == 3:
# Calculate for Sphere
radius = float(input("Enter the radius of the sphere: "))
surface_area = 4 * math.pi * radius ** 2
volume = (4/3) * math.pi * radius ** 3
print(f"Total surface area of the sphere: {surface_area}")
print(f"Volume of the sphere: {volume}")
elif choice == 4:
# Exit the program
print("Exiting the program.")
break
Stores the
user's
menu
choice int choice
Stores the
side
length of
side float the cube
Stores the
length of
the
length float cuboid
Stores the
width of
the
width float cuboid
Stores the
height of
the
height float cuboid
Stores the
radius of
the
radius float sphere
Stores the
calculated
surface_ surface
area float area
Stores the
calculated
volume float volume
ALGORITHM:
Display Menu:
Show a menu with options for calculating the surface area and volume of a cube, cuboid,
or sphere, and an option to exit.
If the choice is 1, prompt the user for the side length of the cube and calculate its surface
area and volume.
If the choice is 2, prompt the user for the length, width, and height of the cuboid and
calculate its surface area and volume.
If the choice is 3, prompt the user for the radius of the sphere and calculate its surface
area and volume.
If the choice is 4, exit the program.
If the choice is invalid, display an error message.
Repeat:
OUTPUT:
Example 1:
Input:
Choice: 1
Side length: 3
Output:
Total surface area of the cube: 54.0
Volume of the cube: 27.0
Example 2:
Input:
Choice: 2
Length: 2
Width: 3
Height: 4
Output:
Total surface area of the cuboid: 52.0
Volume of the cuboid: 24.0
Example 3:
Input:
Choice: 3
Radius: 5Output:
Total surface area of the sphere: 314.1592653589793
Volume of the sphere: 523.5987755982989