ARTIFICIAL
INTELLIGENCE
PRACTICAL FILE
~ Poorvi Gupta 9th B, 27
# Question 1 :
# WAP to find the area of a circle or a
rectangle.
a = int(input("Enter 1 to find the area of a
circle and type 2 to find the area of a
rectangle:"))
if a==1:
r = int(input("Enter a radius:"))
area = r**2*3.14
print ("The area of the circle is:",
area)
elif a==2:
l = int(input("Enter a length:"))
b = int(input("Enter a breadth:"))
c = l*b
print ("The area of the rectangle is", c)
else:
print ("Enter a valid no.")
# Question 2:
# WAP to input the first name and the last
name to print the full name.
fn = input("Enter your first name:")
ln = input("Enter your last name:")
fulln = fn + " " + ln
print(fulln)
# Question 3:
# WAP to convert length given in kilometre in
meter
a = int(input("Enter a length in
kilometre:"))
b = a*1000
print("The given length in meters is", b)
# Question 4:
# WAP to calculate Simple interest if time is
2 and the principal amount and rate of
interest has to be inputed by the user.
P = int(input("Enter the principal amount:"))
R = int(input("Enter the rate of interest:"))
T = 2
Si = (P*R*T)/100
print ("The simple interest is", Si)
# Question 5:
# WAP to calculate average marks of Maths,
Science, English.
a = float(input("Enter your English marks:"))
b = float(input("Enter your Science marks:"))
c = float(input("Enter your Maths marks:"))
am = (a+b+c)/3
print("Average marks of 3 subject are", am)
# Question 6:
# WAP to calculate discounted amount with
discount %.
a = float(input("Enter an amount:"))
d = float(input("Enter the discount:"))
da = a - d
dp = (d/a)*100
print("The discounted amount is", da ,"and
the discount percentage is", dp ,"%")
# Question 7:
# WAP to calculate the surface area and the
volume of a cuboid.
a = int(input("Enter a length:"))
b = int(input("Enter a breadth:"))
c = int(input("Enter a height:"))
sa = 2*((a*b)+(b*c)+(c+a))
print("The surface area of the cuboid is",
sa)
v = a*b*c
print("The volume of the cuboid is", v)
# Question 8:
# WAP to input marks and allocate grades as
per criteria - marks below 70 is fail, 70 and
above is C, 80 and above is B and 90 and
above is A.
m = float(input("Enter your marks:"))
if m >= 90:
print("You received A grade")
elif m >= 80:
print("You received B grade")
elif m >= 70:
print("You received C grade")
else:
print("You failed")
# Question 9:
# WAP to find greatest among Three Numbers.
num1 = int(input("Enter a number: "))
num2 = int(input("Enter a number: "))
num3 = int(input("Enter a number: "))
if num1 > num2 and num1 > num3:
print("The greatest number is", num1)
elif num2 > num1 and num2 > num3:
print("The greatest number is", num2)
else:
print("The greatest number is", num3)
# Question 10:
# WAP to input the age and find if the person
is a minor, major or senior citizen.
a = int(input("Enter your age"))
if a <= 17:
print("You are a minor")
elif a >= 18 and a<= 59:
print("You are a major")
else:
print("You are a senior citizen")
# Question 11:
# WAP to input a salary, if the salary is
more than 90000 and 10% bonus of the salary
and if the salary is more than 60000 and 20%
bonus of the salary else no bonus. Calculate
the total salary whose formula is salary +
bonus.
s = float(input("Enter your salary"))
if s > 90000:
b = s*0.1
elif s > 60000:
b = s*0.2
else:
b = 0
c = s + b
print("Your total salary is", c)
# Question 12:
# WAP to print the personal details of a
person.
name = input("Enter your full name:")
cs = input("Enter your class and section:")
schname = input("Enter your school name:")
Fname = input("Enter your father's name:")
Mname = input("Enter your mother's name:")
print("*Personal Information*")
print("Name:", name)
print("Father's name", Fname)
print("Mother's name", Mname)
print("Class:", cs)
print("School name:", schname)
# Question 13:
# WAP to find the cube or a square of a
number.
a = int(input("Enter a number"))
b = int(input("Enter 1 to find the square and
enter 2 to find the cube."))
if b == 1:
c = a**2
print("The square of the given no. is",c)
elif b == 2:
c = a**3
print("The cube of the given no. is", c)
else:
print("Kindly enter a valid no.")
# Question 14:
# WAP to check if the inputed no. is
positive, negative or 0.
N = int(input("Enter any number"))
if N == 0:
print("The given no. is 0")
elif N > 0:
print("The given no. is positive")
else:
print("The given no. is negative")
# Question 15:
# WAP to make a simple calculator.
print("Select operation: +, -, *, /")
op = input("Enter operator: ")
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
if op == "+":
print("Result:", a + b)
elif op == "-":
print("Result:", a - b)
elif op == "*":
print("Result:", a * b)
elif op == "/":
if b == 0:
print("Error: Division by zero")
else:
print("Result:", a / b)
else:
print("Invalid operator")
# Question 16:
# WAP to check if a year is a leap year.
y = int(input("Enter a year: "))
if (y % 4 == 0):
print(y, "is a Leap Year")
else:
print(y, "is not a Leap Year")
# Question 17:
# WAP to make an temperature converted of
Celsius and Fahrenheit
print("1. Celsius to Fahrenheit")
print("2. Fahrenheit to Celsius")
choice = int(input("Enter choice (1/2): "))
temp = float(input("Enter temperature: "))
if choice == 1:
print("In Fahrenheit:", (temp * 9/5) +
32)
elif choice == 2:
print("In Celsius:", (temp - 32) * 5/9)
else:
print("Invalid choice")
# Question 18:
# WAP to check whether a transaction results
in profit, loss, or no profit/loss based on
cost price and selling price.
cp = float(input("Enter Cost Price: "))
sp = float(input("Enter Selling Price: "))
if sp > cp:
print("Profit:", sp - cp)
elif sp < cp:
print("Loss:", cp - sp)
else:
print("No Profit, No Loss")
# Question 19:
# WAP to print the day of the week when a
number (1–7) is entered by the user.
day = int(input("Enter day number (1-7): "))
if day == 1:
print("Monday")
elif day == 2:
print("Tuesday")
elif day == 3:
print("Wednesday")
elif day == 4:
print("Thursday")
elif day == 5:
print("Friday")
elif day == 6:
print("Saturday")
elif day == 7:
print("Sunday")
else:
print("Invalid day number")
# Question 20:
# WAP to calculate the percentage of a
student of each subject.
mo = float(input("Enter marks obtained: "))
tm = float(input("Enter total marks: "))
if tm > 0:
percentage = (mo/tm) * 100
print("Percentage:", percentage, "%")
else:
print("Total marks cannot be 0")
# Question 21:
# WAP to print first 10 multiples of 7 using
for loop.
print("The first ten multiples of 7 are:")
for i in range(1,11):
product = 7*i
print(product)
# Question 22:
# WAP to find the sum of first 10 natural
numbers.
sum = 0
for i in range(1,11):
sum = sum + i
print ("The sum of first ten natural numbers
is ",sum)
# Question 23:
# WAP to print “Happy New Year 2026” five
times using range function.
a = "Happy New Year 2026"
for i in range(1,6):
print(a)
# Question 24:
# WAP to print the next 10 numbers of the
inputed no. using a while loop.
i = int(input("Enter a number: "))
t = i + 11
while(i<t):
print(i)
i = i+1
# Question 25:
'''Create a list1= [5,10,15,20].
Add elements [14,18,11] in list1 using extend
function.
Now sort the final list in ascending order
and display it.'''
list1= [5,10,15,20]
l = [14,18,11]
[Link](l)
[Link]()
print(list1)
# Question 26:
''' WAP to create a list and perform the
following tasks on the list.
a) Print the whole list.
b) Add one element at the end of the list.
c) Add one element at the second position in
the list.
d) Remove the item of third index. '''
l = [1,2,3,4,5,6,7,8,9,10]
print(l)
[Link](11)
[Link](2,7)
[Link](3)
print(l)
# Question 27:
# WAP to check is a list is sorted or not.
(ascending or descending order too)
a = []
n = int(input("Enter number of elements: "))
for i in range(n):
x = int(input("Enter element: "))
[Link](x)
b = []
for i in range(len(a)):
[Link](a[i])
c = input("Do you want the list to be checked
for ascending or descending order? (a/d): ")
c = [Link]()
if c == "a":
[Link]()
if b == a:
print("The list is sorted in
ascending order.")
else:
print("The list is not sorted in
ascending order.")
elif c == "d":
[Link](reverse=True)
if b == a:
print("The list is sorted in
descending order.")
else:
print("The list is not sorted in
descending order.")
else:
print("Kindly enter a valid input.")
# Question 28:
# WAP to find the sum of first 20 even and
odd nos. seperately.
Sum = 0
for i in range (2,41,2):
Sum = Sum+i
print("The sum of first 20 even nos. is :
",Sum)
sum = 0
for i in range (1,42,2):
sum = sum+i
print("The sum of first 20 odd nos. is :
",sum)
# Question 29:
# WAP to display square of even numbers and
cube of odd numbers.
for i in range (0,10):
a = int(input("Enter a number:"))
if a%2 == 0:
print(a**2)
else:
print(a**3)
# Question 30:
# WAP to add each element of the list
l = [10,20,30,40,50]
sum = 0
for i in l:
sum = sum+i
print("The sum is",sum)
# Question 31:
# WAP to display the elements of the list
l = [1,5,2,7,8,34,12,54,78,90]
for i in l:
print(i)
# Question 32:
# WAP to display each element of the list
using len and range function.
l = [1,2,3,4,5,6,7,8,9,10]
for i in range (len(l)):
print(l[i])
# Question 33:
# WAP to make a bank simulator
balance = 0
print("Balance: 0.00")
while True:
a = input("Do you want to withdraw or
deposit money?(Press w for withdrawal and d
for deposition.)")
[Link]()
if a == "w":
if balance == 0:
print("The amount can not be
withdrawn as the balance is 0. Please make a
deposition first.")
else:
w = float(input("Enter the amount
to be withdrawn: "))
if w < 0 :
print("Sorry, Withdrawal can
not be in negative.")
elif w > balance:
print("Sorry, The withdrawal
can not be greater than the balance.")
else:
balance = balance - w
print("Remaining balance:
",balance)
elif a == "d":
d = float(input("Enter the amount to
be deposited: "))
if d < 0:
print("Sorry, Deposition can not
be negative.")
else:
balance = balance + d
print("Remaining balance:
",balance)
else:
print("The input is invalid.")
p = input("Do you want to
continue?(y/n)")
[Link]()
if p == "y":
continue
elif p == "n":
break
else:
print("Kindly enter a valid leter y
or n.")
# Question 34:
# WAP to display each element in reverse
order.
l = [6,9,2,3,5,11,78,32,90,32]
x = len(l) - 1
for i in range (x,-1,-1):
print(l[i])
# Question 35:
# WAP to display all the positive numbers
from the list, assuming that a list is a
mixture of both positive and negative
numbers.
l = [1,-6,3,89,-54,-8,67,-54,0]
for i in range (len(l)):
if l[i]>0:
print(l[i])
# Question 36:
# WAP to print N odd numbers
N = int(input("Enter the no. terms: "))
m = N+1
for i in range(1,m):
print(2*i-1,end=",")
# Question 37:
# WAP to print the sum of all numbers stored
in a list
s = 0
for i in [10,27,33,45,5,60,7,81,9]:
s = s+i
print("The sum is ",s)
# Question 38:
# WAP to print the Fibonacci series
n = int(input("Enter a number: "))
a, b = 0, 1
for i in range(n):
print(a, end=" ")
a, b = b, a + b
# Question 39:
# WAP to find the factorial of a inputed
number
n = int(input("Enter a number: "))
factorial = 1
for i in range(1, n+1):
factorial = factorial * i
print("Factorial of", n, "is", factorial)
# Question 40:
# WAP to check if a number is prime or not
l =[]
n = int(input("Enter a number: "))
m = n +1
for i in range(2,m):
if n%i == 0:
[Link](i)
if len(l) > 1:
print(n," is not a prime number. It's
factors are: ")
print (l)
else:
print(n," is a prime number. It's factors
are: ")
print("[",n,",1]")
# Question 41:
# WAP to count the number of vowels and
consonants in a word.
a = input("Enter a string: ")
[Link]()
vowels = "aeiou"
x = 0
y = 0
for i in a:
if [Link]():
if i in vowels:
x += 1
else:
y += 1
print("Number of vowels:", x)
print("Number of consonants:", y)
# Question 42:
# WAP to check if a number is a palindrome or
not
a = input("Enter a word or number: ")
if a == a[::-1]:
print(a, "is a palindrome")
else:
print(a, "is not a palindrome")
# Question 43:
# WAP to print reverse of a number
a = int(input("Enter a number: "))
x = 0
while a > 0:
b = a % 10
x = x * 10 + b
a = a // 10
print("Reversed number is:", x)
# Question 44:
# WAP to check if a number is Armstrong
number or not.
a = int(input("Enter a number: "))
b = a
sum = 0
while a > 0:
x = a % 10
sum += x**3
a = a // 10
if sum == b:
print(b, "is an Armstrong number")
else:
print(b, "is not an Armstrong number")
# Question 45:
# WAP to find the Greatest common divisor of
two numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a < b:
c = a
else:
c = b
for i in range(c, 0, -1):
if a % i == 0 and b % i == 0:
print("The Greatest common divisor
is:", i)
break
# Question 46:
# WAP to make a to-do list.
tasks = []
while True:
print("1. Add Task 2. Show Tasks 3.
Delete Task 4. Exit")
a = input("Choose option: ")
if a == "1":
b = input("Enter task: ")
[Link](b)
print("Task added!")
elif a == "2":
if len(tasks) == 0:
print("No tasks found")
else:
for i in range(len(tasks)):
print(i+1, tasks[i])
elif a == "3":
b = int(input("Enter task number to
delete: "))
if 0 < b <= len(tasks):
print("Deleted:", [Link](b-1))
else:
print("Invalid task number")
elif a == "4":
break
else:
print("Invalid input")
# Question 47:
# WAP to split a list into even and odd
numbers
a = [1, 2, 3, 4, 5, 6]
e = []
o = []
for i in range(len(a)):
if a[i] % 2 == 0:
[Link](a[i])
else:
[Link](a[i])
print("Even list:", e)
print("Odd list:", o)
# Question 48:
# WAP to see if two numbers are co-prime.
a = int(input("Enter a: "))
b = int(input("Enter b: "))
g = 1
for i in range(1, min(a, b) + 1):
if a % i == 0 and b % i == 0:
g = i
if g == 1:
print("Co-prime numbers")
else:
print("Not co-prime")
# Question 49:
# WAP to see if a string is an Isogram
a = input("Enter string: ")
flag = True
for i in range(len(a)):
for j in range(i+1, len(a)):
if a[i] == a[j]:
flag = False
if flag:
print("Isogram")
else:
print("Not an isogram")
# Question 50:
# WAP to display each element in reverse
order
a = [1, 2, 3, 4, 5]
b = []
for i in range(len(a)-1, -1, -1):
[Link](a[i])
print(b)