Practical file of AI
[1] To print personal information like Name, Father’s Name,
Class, and School Name.
print("Name – ........................")
print("Father's Name - ............................")
print("Class - IX")
print("......................................")
[2] To print the following patterns using multiple print
commands-
* *****
** ****
*** ***
**** **
***** *
# Part A
print("*")
print("* * ")
print("* * *")
print("* * * *")
print("* * * * *")
# Part B
print("* * * * *")
print("* * * *")
print("* * *")
print("* * ")
print("*")
or
To print:
* *****
** ****
*** ***
**** **
***** *
rows = 5
for i in range(1, rows + 1):
for j in range(i):
print('*', end=' ')
print()
[3] To find the square of the number 7
#Method 1
print(7**2)
#Method 2
print(7*7)
#Mehtod 3
import math
print([Link](7,2))
[4] To find the sum of two numbers 15 and 20.
[5] To convert length given in kilometers into meters.
[6] To print the table of 5 up to five terms.
[7] To calculate Simple Interest if the principle_amount = 2000
rate_of_interest = 4.5 time = 10
#Program 4
print(15+20)
#Program 5
kms=5
print(kms,"kms = "5*1000, " meters")
#Program 6
print(5," * ", 1, " = ", 5*1)
print(5," * ", 2, " = ", 5*2)
print(5," * ", 3, " = ", 5*3)
print(5," * ", 4, " = ", 5*4)
print(5," * ", 5, " = ", 5*5)
#Program 7
principle_amount=2000
rate_of_nt=4.5
time=10
print("Simple Interest -", (principal*rate_of_int*time)/100)
Input Function
[8] To calculate Area and Perimeter of a rectangle
l=int(input("Enter length:"))
w=int(input("Enter Width:"))
area=l*w
Perimeter= 2(l+w)
print("Area of Rectangle:",area)
print("Area of Perimeter:",Perimeter)
[9] To calculate Area of a triangle with Base and Height
Base=float(input("Enter base:"))
Height=float(input("Enter height:"))
area_of_triangle=Base*Height/2
print("Area of triangle:",area_of_triangle)
[10] To calculating average marks of 3 subjects
mm=int(input("Enter Maximum marks of each subject:"))
eng=float(input("Enter marks of English:"))
maths=float(input("Enter marks maths:"))
ai=float(input("Enter AI:"))
print("Maximum marks of each subject:",mm)
avg=(eng+maths+ai)/3
print("Average of 3 subjects marks:",avg)
[11] To calculate discounted amount with discount %
bill_amt=float(input("Enter Bill Amount:"))
dis_per=float(input("Enter discount in (%):"))
dis=bill_amt*(dis_per/100)
net_amt=bill_amt-dis
print("Discount Amount:",dis)
print("Net Amount:",net_amt)
[12] To calculate Surface Area and Volume of a Cuboid
length=float(input("Enter Length:"))
breadth=float(input("Enter Breadth:"))
height=float(input("Enter Height:"))
area_cuboid = 2 * ((length * breadth) + (breadth * height) +
(height * length))
volume = length * breadth * height
print("Surface area of the cuboid having length ", length, " breadth
", breadth, " and height ", height, " is --> ", area_cuboid)
print("Volume of cuboid having length", length, " breath", breadth,
" and height ", height, " is --> ", volume)
Programs based on Lists
[13] Create a list in Python of children selected for science quiz
with the following names- Arjun, 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
stu_lst=['Arjun','Sonakshi','Vikram','Sandhya','Sonal','Isha','Kartik'
]
#Print the whole list
print(stu_lst)
#Delete the name Vikram
#method - 1
#del stu_lst['Vikram']
#Method - 2
#stu_lst.pop(stu_lst.index('Vikram'))
#Add the name "Jay" at the end
stu_lst.append('Jay')
#remove the item at second position
stu_lst.remove(stu_lst[2])
print(stu_lst)
[14] 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
num=[23,12,5,9,65,44]
#printing the length of the list
print("Length of list is:", len(num))
#Print the elements from second to fourth position using positive
indexing
print("2nd to 4th Position elements:",num[1:4])
#Print the elements from position third to fifth using negative
indexing
print("Print the elements from position third to fifth using negative
indexing",num[-4:-1])
15] Create a list of the first 10 even numbers, add 1 to each list
item, and print the final list.
l=list(range(2,21,2))
print(l)
for i in range(len(l)):
l[i]=l[i]+1
print(l)
[16] Create a list List_1=[10,20,30,40]. Add the elements
[14,15,12] using the extend function. Now sort the final list in
ascending order and print it.
list_1=[10,20,30,40]
list_1.extend([14,15,12])
list_1.sort()
print(list_1)
17] Program to check if a person can vote
age=int(input("Enter Age:"))
if age>=18:
print("Person is eligible for vote")
else:
print("Person is not eligible for vote")
[18] To check the grade of a student
per=float(input("Enter Percentage:"))
if per>=91 and per<=100:
print("Grade:A")
elif per>=71 and per<=90:
print("Grade:B")
elif per>=51 and per<=70:
print("Grade:C")
elif per>=35 and per<=50:
print("Grade:D")
else:
print("Imrovemenet required...")
[19] Input a number and check if the number is positive,
negative, or zero, and display an appropriate message
n=int(input("Enter any number to check:"))
if n>0:
print("No is positive")
elif n<0:
print("No is negative")
else:
print("Zero")
[20] To print first 10 natural numbers
for i in range(1,11):
print(i)
[21] To print first 10 even numbers
for i in range(1,21,2):
print(i)
[22] To print odd numbers from 1 to n
n=int(input("Enter n:"))
for i in range(1,n,2):
print(i)
[23] To print sum of first 10 natural numbers
s=0
for i in range(1,11):
s+=i
print(s)
[24] Program to find the sum of all numbers stored in a list
l=[10,20,30,40,50]
s=0
for i in l:
s+=i
print(s)