St Raphael’s Academy
Class IX AI practical program
4. Program for calculating Simple Interest
Principle = int (input("Enter the Principle amount :")) rate int (input("Enter the
Rate of Interest :"))
time= int (input("Enter Time:"))
si = (principle rate time)/100
print("The Simple Interest is:",si)
5. Program for calculating Area of a Circle
Radius = int (input("Enter the Radius of a Circle:"))
area =3.14 *(radius**2)
print("The Area of a Circle is :", area)
6. Program for calculating area and perimeter of a rectangle
length =int (input("Enter the length of a Rectangle:"))
breadth =int(input("Enter the breadth of a Rectangle:"))
area = length * breadth
peri = 2* (length+breadth)
print("\n")
print("The Area of a Rectangle is:", area)
print ("The Perimeter of a Rectangle is:", peri)|
7. Program for converting meteres into centimeters
meter = int (input("Enter the distance in meters:"))
cms= meter * 100
print("The Conversion of: ",meter," meters into centimeters is: ",cms)
8. Program for finding and replacing the text in a list
cars = ["Audi", "Mercedees", "Tesla", "Jaguar", "GM"]
print("The list is: \n",cars)
brand1= input("Enter a Brand to search for: ")
brand2 = input("Enter a Brand with which to replace: ")
value = cars.index(brand1)
cars[value]=brand2
print("The list will now be: \n",cars)
9. Program for arranging the elements in a list (ascending, descending and
reverse order)
sports = ["Cricket", "Football", "Volleyball", "Kabbadi", "Tennis"]
print("\n The original list is: \n", sports)
sports.sort()
print("\n The list in ascending order is: \n", sports)
sports.reverse()
print("\n\n After reversal the list will be: \n", sports)
sports.sort(reverse=True)
print("\n\n The list in descending order is: \n", sports)
10. Program for printing gross profit
cp = int(input("Enter Cost Price of a Product :"))
sp = int(input(“Enter selling price of a Product :"))
result=float (sp-cp)
print("\n")
if(result>0):
print("Gross Profit is:", result)
else:
print("Gross Loss is:", result)|
11. Write the Python code for swapping values using third variable.
x=int(input(“Enter the first number”))
y=int(input(“Enter the second number”))
print(“The value of x before swapping”)
print(“The value of y before swapping”)
z=x
x=y
y=z
print(“The value of x after swapping is :“,x)
print(“The value of y after swapping is :”,y)
12. Write a program to make a simple calculator.
x=int(input(“Enter the first number :”))
y=int(input(“Enter the second number :”))
op=input(“Enter the operator :”))
if op==”+”:
print(“The Addition of “,x,” and ”,y,” is “,x+y)
elif op==”-”:
print(“The subtraction of “,x,” and ”,y,” is “,x-y)
elif op==”*”:
print(“The Multiplication of “,x,” and ”,y,” is “,x*y)
elif op==”/”:
print(“The Division of “,x,” and ”,y,” is “,x/y)
else:
print(“Invalid operator “)
13. Write a program to calculate sum of numbers till number given by the
user
num=int(input(“Enter any number “))
i=1
sum=0
while (i < num):
sum=sum+ i
i=i+1
print(“Sum of the numbers is “,sum)
14. Write a program to count the number of vowels in the string
str= input(“Enter the string “)
count=0
str=str.lower()
for i in str:
if i in (‘a’,’e’,’i’,’o’,’u’):
count=count+1
print(“Number of vowels in the string are “,count)
15. Write a program to display the name of the city with its temperature
value.
city=['Delhi','Mumbai','KolKata','Chennai']
temp=[43,36,42,38]
search=input('enter the name of the city')
find = -1
for x in range(0,len(city)):
if city[x]==search:
pos=x
temp=temp[x]
find=1
if find==-1:
print("City not found")
else:
print("temperature of ",city[pos], ' in ',temp)