Artificial Intelligence
Subject Code- 417
Practical File
Kendriya Vidyalaya New Cantt, Shift-1
Prayagraj
Students Details Submitted To:-
Name: ………………………… Mr.
Class: ….………..
Roll No.: ………..
INDEX
S. NO. PROGRAM PAGE NO.
1 Write a program in python to Print 5 lines about yourself using print() function. 1
2 Write a program in python to convert the value given in centimetre into inches 2
3 Write a program in python to input two integers and find their addition (Sum) 3
4 Write a program in python to print different values (integer, Float, String, Boolean) 4
5 Write a program in python to print simple interest using Formula si=(P*R*T)/100 5
6 Write a program in python to check the given year is a leap year or not 6
7 Write a program in python to find whether the number entered by the user is Even or 7
Odd
8 Write a program in python on example of floor division 8
9 Write a program in Python to Print first 10 Odd Natural Numbers 9
10 Write a program in python to find whether the number entered by the user is Negative, 10
Positive, or Zero.
11 Write a program in python that reads two numbers and perform all arithmetic operations 11
on them.
12 Write a program that reads two numbers and an arithmetic operator and display the 12
result according to the operator used.
13 Write a program to find maximum and minimum among 3 numbers. 13
14 Write a program to find maximum and minimum among 3 numbers using list. 14
15 Write a program in python to display your name and age in separate line. Also tell how 15
can you print your name and age on the same line?
16 Write a program in python to calculate the percentage of students who secured marks in 16
5 subjects out of 100 in each.
17 Write a program in python to calculate Area and Perimeter of a rectangle 17
18 Write a program in python to swap values of two variables. 18
19 Write a program in python to display the multiplication table. 19
20 Write a program in python to calculate profit or loss 20
#Program-1: Write a program in python to Print 5 lines about yourself
using print() function
Program:
# Print 5 lines about yourself
print("Biodata")
print("Name – Ashok Kumar Thakur")
print("Class - IX")
print("Roll No. - 21")
print("School – PM SHRI KV NEW CANTT,SHIFT1 PRAYAGRAJ")
print("Subject– Artificial Intelligence")
Output
Biodata
Name – Ashok Kumar Thakur
Class - IX
Roll No. - 9
School – PM SHRI KV NEW CANTT,SHIFT1 PRAYAGRAJ
Subject– Artificial Intelligence
#Program-2: Write a program in python to convert the value given in
centimetre into inches
Program:
cm_distance = float(input("Enter the distance in cm: "))
inch_distance = cm_distance/2.54
print("Distance in inch:", inch_distance)
Output
Enter the distance in cm: 10
Distance in inch: 3.937007874015748
Enter the distance in cm: 20
Distance in inch: 7.874015748031496
OR
Program:
cm_distance = float(input("Enter the distance in cm: "))
inch_distance = cm_distance/2.54
print('Distance in inch: {0:.2f}'.format(inch_distance))
Output
Enter the distance in cm: 10
Distance in inch: 3.94
Enter the distance in cm: 20
Distance in inch: 7.87
#Program-3: Write a program in python to input two integers and find
their addition (Sum).
Program:
# input two numbers: value of a and b
a = int(input("Enter A: "))
b = int(input("Enter B: "))
# find sum of a and b and assign to c
c = a+b
print("Sum: ",c)
Output
Enter A: 100
Enter B: 200
Sum: 300
Explanation:
Here, we are reading two values and assigning them in variable a and b - to input the
value, we are using input() function, by passing the message to display to the user.
Method input() returns a string value, and we are converting the input string value
to the integer by using int() method.
After that, we are calculating the sum of a and b and assigning it to the variable c.
And then, printing the value of c which is the sum of two input integers.
#Program-4: Write a program in python to print different values (integer,
Float, String, Boolean)
Program:
# variable with integer value
a=12
# variable with float value
b=12.56
# variable with string value
c="Hello"
# variable with Boolean value
d=True
# printing all variables
print(a)
print(b)
print(c)
print(d)
Output
12
12.56
Hello
True
#Program-5: Write a program in python to print simple interest using
Formula si=(P*R*T)/100
To calculate simple interest, we use the following formula,
(P * R * T) / 100
Where,
P – Principle amount
R – Rate of the interest, and
T – Time in the years
# Python program to find simple interest
p = float(input("Enter the principle amount : "))
r = float(input("Enter the rate of interest : "))
t = float(input("Enter the time in the years: "))
# calculating simple interest
si = (p*r*t)/100
# printing the values
print("Simple Interest: ", si)
Output
Enter the principle amount : 10000
Enter the rate of interest : 3.5
Enter the time in the years: 1
Simple Interest: 350.0
#Program-6: Write a program in python to check the given year is a leap
year or not
Program:
# input the year
y=int(input('Enter the value of year: '))
# To check for non century year
if y%400==0 or y%4==0 and y%100!=0:
print('The given year is a leap year.')
else:
print('The given year is a non-leap year.')
Output
RUN 1:
Enter the value of year: 2020
The given year is a leap year.
RUN 2:
Enter the value of year: 2022
The given year is a non-leap year.
#Program-7: Write a program in python to find whether the number
entered by the user is Even or Odd
Program:
num = int(input("Enter a number: "))
if (num % 2) == 0:
print(num, " is Even number")
else:
print(num, " is Odd number")
Output
Enter a number: 6
6 is Even number
Enter a number: 5
5 is Odd number
#Program-8: Write a program in python on example of floor division
Program:
# python program to find floor division
a = 10
b = 3
# finding division
result1 = a/b
print("a/b = ", result1)
# finding floor division
result2 = a//b
print("a/b = ", result2)
Output
a/b = 3.3333333333333335
a/b = 3
#Program-9: Write a program in Python to Print first 10 Odd Natural
Numbers
Program:
print("====The First 10 Odd Natural Numbers====")
i = 1
while(i <= 10):
print(2 * i - 1)
i = i + 1
Output
====The First 10 Odd Natural Numbers====
1
3
5
7
9
11
13
15
17
19
Program-10: Write a program in python to find whether the number
entered by the user is Negative, Positive, or Zero.
Program:
num = int(input("Enter a number: "))
if num == 0:
print("Zero")
elif num > 0:
print("Positive number")
else:
print("Negative number")
Output
Enter a number: 2
Positive number
Enter a number: 0
Zero
Enter a number: -4
Negative Number
Program-11: Write a program in python that reads two numbers and
perform all arithmetic operations on them.
Program:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
#Printing the result for all arithmetic operations
print("Addition: ",num1 + num2)
print("Subtraction: ",num1 - num2)
print("Multiplication: ",num1 * num2)
print("Division: ",num1 / num2)
print("Modulus: ", num1 % num2)
Output
Enter first number: 15
Enter second number: 4
Addition: 19
Subtraction: 11
Multiplication: 60
Division: 3.75
Modulus: 3
Program-12: Write a program that reads two numbers and an arithmetic
operator and display the result according to the operator used.
Program:
num1=int(input("Enter First Number :"))
num2=int(input("Enter Second Number :"))
op=input("Select Operator [+, -, *, /, %] : ")
result=0
if op=='+':
result=num1+num2
elif op=='-':
result=num1-num2
elif op=='*':
result=num1*num2
elif op=='/':
result=num1/num2
elif op=='%':
result=num1%num2
else:
print("Invalid Operator. .. ")
print(num1, op, num2, '=', result)
Output
Enter First Number :10
Enter Second Number :5
Select Operator [+, -, *, /, %] : +
10 * 5 = 50
Program-13: Write a program to find maximum and minimum among 3
numbers.
Program:
num1 = int(input('Enter First number : '))
num2 = int(input('Enter Second number : '))
num3 = int(input('Enter Third number : '))
maxnum=0
if (num1>num2) and (num1>num3):
maxnum=num1
elif (num2>num1) and (num2>num3):
maxnum=num2
else:
maxnum=num3
minnum=0
if (num1<num2) and (num1<num3):
minnum=num1
elif (num2<num1) and (num2<num3):
minnum=num2
else:
minnum=num3
print("The largest of the 3 numbers is : ", maxnum)
print("The smallest of the 3 numbers is : ", minnum)
Output
Enter First number : 10
Enter Second number : 19
Enter Third number : 5
The largest of the 3 numbers is : 19
The smallest of the 3 numbers is : 5
Program-14: Write a program to find maximum and minimum among 3
numbers using lists.
Program:
num1 = int(input('Enter First number : '))
num2 = int(input('Enter Second number : '))
num3 = int(input('Enter Third number : '))
lst = [num1, num2, num3]
print("The largest of the 3 numbers is : ", max(lst))
print("The smallest of the 3 numbers is : ", min(lst))
Output
Enter First number : 10
Enter Second number : 25
Enter Third number : 65
The largest of the 3 numbers is : 65
The smallest of the 3 numbers is : 10
Program-15: Write a program in python to display your name and age in
separate line. Also tell how can you print your name and age
on the same line
Program:
name = input('Enter your name : ')
age = input('Enter your age : ')
print('\n')
#name and age in separate line
print(name)
print(age)
#name and age in same line
print(name, age)
Output
Enter your name : amit
Enter your age : 22
amit
22
amit 22
Program-16: Write a program in python to calculate the percentage of
students who secured marks in 5 subjects out of 100 in each.
Program:
# Python Program to find Total and Percentage of Five Subjects
english = float(input("Please enter English Marks: "))
math = float(input("Please enter Math score: "))
computers = float(input("Please enter Computer Marks: "))
physics = float(input("Please enter Physics Marks: "))
chemistry = float(input("Please enter Chemistry Marks: "))
total = english + math + computers + physics + chemistry
percentage = total / 5
print("\nTotal Marks = %.2f" %total)
print("Percentage = %.2f" %percentage)
Output
Please enter English Marks: 50
Please enter Math score: 53
Please enter Computer Marks: 65
Please enter Physics Marks: 75
Please enter Chemistry Marks: 85
Total Marks = 328.00
Percentage = 65.60
Program-17: Write a program in python to calculate Area and Perimeter
of a rectangle.
Program:
length = int(input(" the length of a rectangle: "))
breadth = int(input(" 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)
Output
the length of a rectangle: 20
the breadth of a rectangle: 10
The Area of a Rectangle is: 200
The Perimeter of a Rectangle is: 60
Program-18: Write a program in python to swap values of two variables.
Program:
num1=int(input("Enter first Number num1="))
num2=int(input("Enter second Number num2="))
# create a temporary variable and swap the values
temp = num1
num1 = num2
num2 = temp
print("After swapping both numbers")
print("The value of first Number num1=", num1)
print("The value of first Number num2=", num2)
Output
Enter first Number num1=10
Enter second Number num2=5
After swapping both numbers
The value of first Number num1= 5
The value of first Number num2= 10
Program-19: : Write a program in python to display the multiplication
table.
Program:
num = int(input("Enter a Number to print the table: "))
# Iterate 10 times from i = 1 to 10
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
Output
Enter a Number to print the table: 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
Program-20: Write a program in python to calculate profit or loss.
Program:
pamt = int(input(" Please Enter the Purchase Amount: "))
samt = int(input(" Please Enter the Sale Amount: "))
if(pamt > samt):
amount = pamt - samt
print("Total Loss Amount = ", amount)
elif(samt > pamt):
amount = samt - pamt
print("Total Profit = ",amount)
else:
print("No Profit No Loss!!!")
Output
Please Enter the Purchase Amount: 100
Please Enter the Sale Amount: 120
Total Profit = 20
Please Enter the Purchase Amount: 100
Please Enter the Sale Amount: 90
Total Loss Amount = 10
Please Enter the Purchase Amount: 50
Please Enter the Sale Amount: 50
No Profit No Loss!!!