Artificial Intelligence
Class IX – A & B
Practical Assignments
1. Input Firstname, Middlename and Lastname from a user and display full name.
Flowchart
Program
#INPUT
fn = input("Enter the first name : ")
mn = input("Enter the middle name : ")
ln = input("Enter the last name : ")
#OUTPUT
print("The name is = ", fn, mn, ln)
Output
Enter the first name : Rishi
Enter the middle name : Kumar
Enter the last name : Dubey
The name is = Rishi Kumar Dubey
2. Input 2 integers from the user and perform addition, subtraction, multiplication and division
(Quotient and remainder) and display the result.
Flowchart
Program
#INPUT
a = int(input("Enter the first integer : "))
b = int(input("Enter the second integer : "))
#CALCULATION
sum = a+b
diff = a-b
prod = a*b
qtn = a//b
rem = a%b
#OUTPUT
print("The sum is = ", sum)
print("The difference is = ", diff)
print("The product is = ", prod)
print("The quotient is = ", qtn)
print("The remainder is = ", rem)
Output
Enter the first integer : 7
Enter the second integer : 3
The sum is = 10
The difference is = 4
The product is = 21
The quotient is = 2
The remainder is = 1
3. Input distance covered and time taken by a car from the user and find the speed of the car.
Flowchart
Program
#INPUT
d = float(input("Enter the distance covered by the car : "))
t = float(input("Enter the time taken by the car : "))
#CALCULATION
v = d/t
#OUTPUT
print("The speed of the car is = ", v)
Output
Enter the distance covered by the car : 50
Enter the time taken by the car : 8
The speed of the car is = 6.25
4. Input Principal, Rate of interest and time period from the user and find the total interest paid
and total amount as per
i. Simple interest
ii. Compound interest
Flowchart
Program
#INPUT
p = float(input("Enter the principal : "))
r = float(input("Enter the rate of interest : "))
t = float(input("Enter the time period : "))
#CALCULATION
SI = p*r*t/100
STA = p + SI
CTA = p*(1 + r/100)**t
CI = CTA - p
#OUTPUT
print("Simple interest paid at the end of tenure = ", SI)
print("Total amound due to simple interest = ", STA)
print("Compund interest paid at the end of tenure = ", CI)
print("Total amound due to compound interest = ", CTA)
Output
Enter the principal : 1000
Enter the rate of interest : 5
Enter the time period : 3
Simple interest paid at the end of tenure = 150.0
Total amound due to simple interest = 1150.0
Compund interest paid at the end of tenure = 157.62500000000023
Total amound due to compound interest = 1157.6250000000002
5. Input 3 sides of a triangle and find its perimeter and area.
Flowchart
Program
import math
#INPUT
a = int(input("Enter the 1st side : "))
b = int(input("Enter the 2nd side : "))
c = int(input("Enter the 3rd side : "))
#CALCULATION
p = (a+b+c)
s = p/2
a = math.sqrt(s*(s-a)*(s-b)*(s-c))
#OUTPUT
print("Perimeter of the triangle is = ", p)
print("Area of the triangle is = ", a)
Output
Enter the 1st side : 5
Enter the 2nd side : 6
Enter the 3rd side : 7
Perimeter of the triangle is = 18
Area of the triangle is = 14.696938456699069
6. Input radius of a circle and find its circumference and area.
Flowchart
Program
import math
#INPUT
r = float(input("Enter the radius : "))
#CALCULATION
p = 2*math.pi*r
a = math.pi*(r**2)
#OUTPUT
print("The perimeter is : ", p)
print("The area is : ", a)
Output
Enter the radius : 5
The perimeter is : 31.41592653589793
The area is : 78.53981633974483
7. Input the values of a, b, c, d from the user and evaluate the following expression:
F = a + b*2 - c/3 + 5(d-1) + 2**3
Flowchart
Program
#INPUT
a = float(input("Enter a : "))
b = float(input("Enter b : "))
c = float(input("Enter c : "))
d = float(input("Enter d : "))
#CALCULATION
F = a + b*2 - c/3 + 5*(d-1) + 2**3
#OUTPUT
print("The resultant value is : ", F)
Output
Enter a : 10
Enter b : 3
Enter c : 12
Enter d : 7
The resultant value is : 50.0
8. Input a list of numbers and display the elements at even position.
Program
#INPUT
L = eval(input("Enter the list of numbers : "))
#CALCULATION
LE = L[0:len(L):2]
#OUTPUT
print("The elements in the even positions in the list are : ", LE)
Output
Enter the list of numbers : [5.2, 9.6, 10.4, 8.75, 45]
The elements in the even positions in the list are : [5.2, 10.4, 45]
9. Input a list of numbers and display the following:
i. Size of the list
ii. Sum of all numbers in the list
iii. Maximum element in the list
Program
#INPUT
L = eval(input("Enter the list of numbers : "))
#CALCULATION & OUTPUT
print("The size of list : ", len(L))
print("The sum of all elements in the list : ", sum(L))
print("The maximum element in the list : ", max(L))
Output
Enter the list of numbers : [6, 9, 2, 4, 5]
The size of list : 5
The sum of all elements in the list : 26
The maximum element in the list : 9
10. Define L=[7,9,2,5,4] and do the following:
i. Delete the last element from L
ii. Delete the value 9 from L
iii. All two elements 1, 3 at the end of L
iv. Insert 6 at index 3 of L
v. Display the latest contents of L
Program
L = [7,9,2,5,4]
#CALCULATION
L.pop()
L.remove(9)
L.extend([1, 3])
L.insert(3, 6)
#DISPLAY
print("The final content of L is = ", L)
Output
The final content of L is = [7, 2, 5, 6, 1, 3]
___________