Practical File
Artificial Intelligence
Class 10
Session : 2024-25
Student details-
Name: Ishita Singhal
Roll no.: 10222
Class: 10
Section: B
Teacher incharge: Ms Surbhi
Bhardwaj
Index
S Assignment Pg
No. No.
Write a program to calculate simple interest when amount, rate,
1 time are given in the code.
Write a program to calculate area and perimeter of square, circle
2 and rectangle
Write a program to print 1-20
3
Write a program to convert temperature from fahrenheit to celcius
4
Write a program to calculate average marks of three subjects
5
Write a program to calculate discounted amount with discount
6 percent
Write a program to calculate surface area and volume of a cuboid
7
Write a program to check if a number is positive and print
8 appropriate message
Write a program to check if a person can vote
9
Write a program to print grade of a student
10
Write a program to find sum of all numbers stored in a list
11
Write a program to add natural numbers till n
12
Write a program to calculate energy using the formula mgh
13
Write a program to calculate distance using formula : distance =
14 ut+1/2at^2
Write a program to unlock your phone using pin or password and
15 generate appropriate message
Write a program with which a tours and travels company charges
16 their customers accordingly
Write a program to check if a number is armstrong or not
17
Write a program to find the largest of three user input numbers
18
Write a program to print the multiplication table of a user input
19 number
Write a program to generate the following pattern
20
Write a program to reverse entered number
21
Write a program to check if entered number is palindrome or not
22
Write a program to demonstrate the use of floor division and
23 modulo operator in python
Write a program to implement an increment to the employees
24 based on their appraisal score
Write a program to sum all odd and even numbers till n separately
25
Q1. Write a program to calculate simple interest when amount, rate,
time are given in the code.
SOURCECODE
#calculate the simple interest
principleAmount = 2000
roi = 4.5
time = 10
simpleInterest = (principleAmount * roi * time)/100
print("Principle amount is Rs:",principleAmount)
print("Rate of interest is :",roi,"% p.a.")
print("Time is :",time,"years")
print("Simple interest is Rs:",simpleInterest)
OUTPUT
Principle amount is Rs: 2000
Rate of interest is : 4.5 % p.a.
Time is : 10 years
Simple interest is Rs: 900.0
Q2. Write a program to calculate area and perimeter of square, circle
and rectangle
SOURCECODE
#WAP to calculate area and perimeter of square,circle,rectangle
shape = input("Enter s(for square), c(for circle) , r(for rectangle) to
calculate area and perimeter: ")
if shape=="s":
side = int(input("Enter side of square"))
print("Area :",side*side)
print("Perimeter :",4*side)
elif shape=="r":
length = int(input("Enter length of rectangle"))
breadth = int(input("Enter breadth of rectangle"))
print("Area :",length*breadth)
print("Perimeter :",2*(length+breadth))
elif shape=="c":
radius = int(input("Enter radius of circle"))
print("Area :",radius*radius*3.14)
print("Circumference :",6.28*radius)
else:
print("Input not recognised try again")
OUTPUT
Enter s(for square), c(for circle) , r(for rectangle) to calculate area and
perimeter: s
Enter side of square10
Area : 100
Perimeter : 40
Enter s(for square), c(for circle) , r(for rectangle) to calculate area and
perimeter: r
Enter length of rectangle10
Enter breadth of rectangle20
Area : 200
Perimeter : 60
Enter s(for square), c(for circle) , r(for rectangle) to calculate area and
perimeter: c
Enter radius of circle10
Area : 314.0
Circumference : 62.800000000000004
Q3. Write a program to print 1-20
SOURCECODE
#WAP to print 1-20
for i in range(1,21):
print(i)
OUTPUT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Q4. Write a program to convert temperature from fahrenheit to celcius
SOURCECODE
#WAP to convert temperature from F-C
f = int(input("Enter temperature in fahrenheit:"))
c = 5/9*(f-32)
print("Temperature in celcius is :"+str(c))
OUTPUT
Enter temperature in fahrenheit:99
Temperature in celcius is :37.22222222222222
Q5. Write a program to calculate average marks of three subjects
SOURCECODE
#WAP to calculate average marks of three subjects
n1 = int(input("Enter marks in maths:"))
n2 = int(input("Enter marks in science:"))
n3 = int(input("Enter marks in english:"))
totalMarks = n1+n2+n3
print("Total marks are "+str(totalMarks))
avg = totalMarks/3
print("Average marks:"+str(avg))
OUTPUT
Enter marks in maths:90
Enter marks in science:78
Enter marks in english:80
Total marks are 248
Average marks:82.66666666666667
Q6. Write a program to calculate discounted amount with discount
percent
SOURCECODE
#WAP to calculate discounted amount with discount %
amt = int(input("Enter amount:"))
discount = int(input("Enter discount percentage:"))
newAmt = amt - amt*discount/100
print("Discounted amount :"+str(newAmt))
OUTPUT
Enter amount:5000
Enter discount percentage:5
Discounted amount :4750.0
Q7. Write a program to calculate surface area and volume of a cuboid
SOURCECODE
#WAP to calculate surface area and volume of a cuboid
l = int(input("Enter length:"))
b = int(input("Enter breadth:"))
h = int(input("Enter height:"))
surfaceArea = 2*(l*b + b*h + h*l)
volume = l*b*h
print("Surface area :"+str(surfaceArea))
print("Volume :"+str(volume))
OUTPUT
Enter length:10
Enter breadth:20
Enter height:15
Surface area :1300
Volume :3000
Q8. Write a program to check if a number is positive and print
appropriate message
SOURCECODE
#WAP to check if the number is positive and print an appropriate
message
n = int(input("Enter number :"))
if n>0:
print("The number is positive")
elif n<0:
print("The number is negative")
else:
print("The number is neither positive nor negative (it is zero)")
OUTPUT
Enter number :72
The number is positive
Q9. Write a program to check if a person can vote
SOURCECODE
#WAP to check if a person can vote
age = int(input("Enter your age:"))
if age >= 18:
print("You are eligible to vote")
else:
print("You are not eligible to vote")
OUTPUT
Enter your age:4
You are not eligible to vote
Q10. Write a program to print grade of a student
SOURCECODE
#WAP to print grade of a student
percentage = int(input("Enter percentage:"))
if percentage >=80:
print("A grade")
elif percentage >=60:
print("B grade")
elif percentage >=40:
print("C grade")
else:
print("Fail")
OUTPUT
Enter percentage:78
B grade
Q11. Write a program to find sum of all numbers stored in a list
SOURCECODE
#WAP to find the sum of all numbers stored in a list
numbers = [6,5,3,8,4,2,5,4,11]
total = 0
for i in numbers:
total = total + i
print("The sum of all numbers is:"+str(total))
OUTPUT
The sum of all numbers is:48
Q12. Write a program to add natural numbers till n
SOURCECODE
#WAP to add natural numbers till n
n = int(input("Enter n:"))
sum_ = 0
for i in range(1,n+1):
sum_ = sum_ + i
print("Sum of all numbers till n is:"+str(sum_))
OUTPUT
Enter n:15
Sum of all numbers till n is:120
Q13. Write a program to calculate energy using the formula mgh
SOURCECODE
#WAP to calculate energy using the formula mgh
m = int(input("Enter mass (in kg):"))
h = int(input("Enter mass (in m):"))
g = 9.8
energy = m*g*h
print("Energy is",energy,"joules")
OUTPUT
Enter mass (in kg):20
Enter mass (in m):10
Energy is 1960.0 joules
Q14. Write a program to calculate distance using formula : distance =
ut+1/2at^2
SOURCECODE
#WAP to calculate distance using formula : distance = ut+1/2at^2
u = int(input("Enter initial velocity(in m/s):"))
t = int(input("Enter time(in s):"))
a = int(input("Enter acceleration(in m/s^2):"))
s = (u*t)+(1/2)*a*t*t
print("Distance is",s,"metres")
OUTPUT
Enter initial velocity(in m/s):18
Enter time(in s):30
Enter acceleration(in m/s^2):5
Distance is 2790.0 metres
Q15. Write a program to unlock your phone using pin or password and
generate appropriate message
SOURCECODE
#WAP to lock or unlock your phone using pin or password and generate
appropriate msg
pin = int(input("Set pin:"))
print("Pin set successfully")
chances = 3
print("You have three chances to unlock your phone")
entered = int(input("Enter pin to unlock phone:"))
while 1==1:
if pin == entered:
print("Phone unlocked")
break
else:
chances = chances - 1
if chances > 0:
print("Incorrect pin. Try again")
print(chances,"chances remaining")
entered = int(input("Enter pin to unlock phone:"))
else:
print("You are out of chances")
break
OUTPUT
Set pin:405989
Pin set successfully
You have three chances to unlock your phone
Enter pin to unlock phone:2345
Incorrect pin. Try again
2 chances remaining
Enter pin to unlock phone:543
Incorrect pin. Try again
1 chances remaining
Enter pin to unlock phone:405989
Phone unlocked
Q16. Write a program with which a tours and travels company charges
their customers accordingly
SOURCECODE
#WAP with which a tours and travels company charges their cuStomers
accordingly
print("A tours and travels company charges their customer")
print("as per following criteria according to customer category.")
print("Category Charges")
print("A 10")
print("B 15")
print("C 12")
print("D 10")
category = input("Enter the category of customer (A/B/C/D):")
if category == "A" or category == "a":
print("Bill is 10 Rs")
elif category == "B" or category == "b":
print("Bill is 15 Rs")
elif category == "C" or category == "c":
print("Bill is 12 Rs")
elif category == "D" or category == "d":
print("Bill is 10 Rs")
else:
print("Invalid input. Try again")
OUTPUT
A tours and travels company charges their customer
as per following criteria according to customer category.
Category Charges
A 10
B 15
C 12
D 10
Enter the category of customer (A/B/C/D):B
Bill is 15 Rs
A tours and travels company charges their customer
as per following criteria according to customer category.
Category Charges
A 10
B 15
C 12
D 10
Enter the category of customer (A/B/C/D):D
Bill is 10 Rs
Q17. Write a program to check if a number is armstrong or not
SOURCECODE
#WAP to check if a number is amrstrong or not
n = int(input("Enter number to check:"))
s=0
x=n
while n > 0:
rem = n%10
s = s + (rem**3)
n = n//10
if s == x:
print(x,"is armstrong")
else:
print(x,"is not armstrong")
OUTPUT
Enter number to check:153
153 is armstrong
Enter number to check:10
10 is not armstrong
Q18. Write a program to find the largest of three user input numbers
SOURCECODE
n1 = int(input("Enter number:"))
n2 = int(input("Enter number:"))
n3 = int(input("Enter number:"))
if n1 > n2:
if n1 > n3:
print(n1,"is the greatest")
else:
print(n3,"is the greatest")
elif n2 > n3:
print(n2,"is the greatest")
else:
print(n3,"is the greatest")
OUTPUT
Enter number:57
Enter number:64
Enter number:49
64 is the greatest
Q19. Write a program to print the multiplication table of a user input
number
SOURCECODE
n = int(input("Enter number:"))
for i in range(1,11):
print(n,"X",i,"=",n*i)
OUTPUT
Enter number:43
43 X 1 = 43
43 X 2 = 86
43 X 3 = 129
43 X 4 = 172
43 X 5 = 215
43 X 6 = 258
43 X 7 = 301
43 X 8 = 344
43 X 9 = 387
43 X 10 = 430
Q20. Write a program to generate the following pattern
1
23
456
7 8 9 10
SOURCECODE
n = int(input("Enter number of lines:"))
x=1
for i in range(1,n+1):
for j in range(1,i+1):
print(x,end=" ")
x=x+1
print()
OUTPUT
Enter number of lines:7
1
23
456
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
Q21. Write a program to reverse entered number
SOURCECODE
n = int(input("Enter number:"))
k=n
reverse = 0
while n > 0:
digit = n % 10
reverse = reverse*10 + digit
n = n//10
print("Reverse of",k,"is",reverse)
OUTPUT
Enter number:20765
Reverse of 20765 is 56702
Q22. Write a program to check if entered number is palindrome or not
SOURCECODE
n = int(input("Enter number:"))
k=n
reverse = 0
while n > 0:
digit = n % 10
reverse = reverse*10 + digit
n = n//10
if k == reverse:
print(k,"is a palindrome")
else:
print(k,"is not a palindrome")
OUTPUT
Enter number:101
101 is a palindrome
Q23. Write a program to demonstrate the use of floor division and
modulo operator in python
SOURCECODE
#WAP to demonstrate the use of floor division (//) and modulo operator
(%) in python
n1 = int(input("Enter number:"))
n2 = int(input("Enter number:"))
print("Floor division (//) returns only the integral value obtained by
division")
print("We can also say it returns the quotient without decimal places")
print(n1,"//",n2,"=",n1//n2)
print()
print("Modulo operatore (%) returns the remainder obtained by
division")
print(n1,"%",n2,"=",n1%n2)
OUTPUT
Enter number:40
Enter number:7
Floor division (//) returns only the integral value obtained by division
We can also say it returns the quotient without decimal places
40 // 7 = 5
Modulo operatore (%) returns the remainder obtained by division
40 % 7 = 5
Q24. Write a program to implement an increment to the employees
based on their appraisal score
SOURCECODE
#WAP to implement an increment to the employees based on their
appraisal score
'''
51-70 - 15%
71-90 - 20%
91-100 - 25%
'''
name = input("Enter name of employee:")
score = int(input("Enter appraisal score:"))
salary = int(input("Enter current salary:"))
if score < 51:
print(name,"is not eligible for increment")
elif score < 71:
salary = salary + salary * 0.15
print(name,"has got an increment of 15%")
print("New salary is",salary)
elif score < 91:
salary = salary + salary * 0.2
print(name,"has got an increment of 20%")
print("New salary is",salary)
elif score < 101:
salary = salary + salary * 0.25
print(name,"has got an increment of 25%")
print("New salary is",salary)
else:
print("Invalid appraisal score entered")
OUTPUT
Enter name of employee:Ishita
Enter appraisal score:54
Enter current salary:1000000
Ishita has got an increment of 15%
New salary is 1150000.0
Enter name of employee:Ishita
Enter appraisal score:27
Enter current salary:100000
Ishita is not eligible for increment
Q25. Write a program to sum all odd and even numbers till n separately
SOURCECODE
#WAP to sum all odd and even natural numbers till n respectively
n = int(input("Enter number:"))
odd = 0
even = 0
for i in range (1,n+1):
if i % 2 == 0:
even = even + i
else:
odd = odd + i
print("Sum of all odd numbers till",n,"is",odd)
print("Sum of all even numbers till",n,"is",even)
OUTPUT
Enter number:25
Sum of all odd numbers till 25 is 169
Sum of all even numbers till 25 is 156