Practical Exam
1. Arithmetic Operations
#WAP to demonstrate Arithmetic Operators
firstvar = int(input(" Enter the first number"))
secondvar = int(input(" Enter the second number"))
print('firstvar + secondvar =',firstvar+secondvar)
print('firstvar - secondvar =',firstvar-secondvar)
print('firstvar * secondvar =',firstvar*secondvar)
print('firstvar / secondvar =',firstvar/secondvar)
print('firstvar // secondvar =',firstvar//secondvar)
print('firstvar ** secondvar =',firstvar**secondvar)
2. Assignment Operators
#WAP to demonstrate Assignment Operators
firstvar = int(input(" Enter the first number"))
firstvar+=5
print('firstvar = firstvar + 5 =>',firstvar)
firstvar-=5
print('firstvar = firstvar - 5 =>',firstvar)
firstvar*=5
print('firstvar = firstvar * 5 =>',firstvar)
firstvar/=5
print('firstvar = firstvar / 5 =>',firstvar)
firstvar%=5
print('firstvar = firstvar % 5 =>',firstvar)
firstvar//=5
print('firstvar = firstvar // 5 =>',firstvar)
firstvar**=5
print('firstvar = firstvar ** 5 =>',firstvar)
3. Comparison operators
#WAP to demonstrate Comparison Operators
firstvar = int(input(" Enter the first number"))
Practical Exam 1
secondvar = int(input(" Enter the second number"))
print('firstvar == secondvar=>',firstvar == secondvar)
print('firstvar != secondvar =>',firstvar != secondvar)
print('firstvar > secondvar =>',firstvar > secondvar)
print('firstvar < secondvar =>',firstvar < secondvar)
print('firstvar >= secondvar =>',firstvar >= secondvar)
print('firstvar <= firstvar =>',firstvar <= secondvar)
4. Logical Operators
#WAP to demonstrate Logical Operators
firstvar = True
secondvar = True
print('firstvar AND secondvar =>',firstvar and secondvar)
print('firstvar OR secondvar =>',firstvar or secondvar)
print('Not firstvar =>',not (firstvar))
5. Compound Interest
#Code to calculate the Compound Interest
principle_amount=float(input("Enter the Principal amount : "))
roi=float(input("Enter the rate of interest : "))
time=float(input("Enter the time period : "))
compound_interest=principle_amount*((1+(roi/100))**time)
print("principle amount : ", principle_amount)
print("rate of interest : ", roi)
print("time : ", time)
print("value of compound interest : ", compound_interest)
6. Factorial of 10
num=10
#The factorial of a number is the product of all the integers from 1 to that number.
factorial=1*2*3*4*5*6*7*8*9*10
#print("The Factorial of "+str(num)+" is "+str(factorial))
print("The Factorial of ",num," is",factorial)
7. nsquare ncube
Practical Exam 2
n = int(input("Enter n: "))
n2, n3, n4 = n ** 2, n ** 3, n ** 4
print("n =", n)
print("n^2 =", n2)
print("n^3 =", n3)
print("n^4 =", n4)
8. WAP TO FIND THE SUM AND AVERAGE OF THE NUMBERS IN LIST
num=[1,2,3,4,5]
sum=num[0]+num[1]+num[2]+num[3]+num[4]
print("The first 5 natural numbers are ",num)
print("The sum of ", num, " is ",sum)
avg=sum/5
print("The average of ", num, " is ",avg)
9. list of first 5 natural numbers and the squares of odd numbers
num=[1,2,3,4,5]
print("The first 5 natural numbers are ", num)
square=[num[0]**2, num[2]**2, num[4]**2]
print("The squares of the odd numbers from first 5 natural numbers are : ",square)
10. list of first 5 multiples of number input by the user
num=int(input("Enter any number : "))
List=[num1, num2, num3, num4, num*5]
print("The first 5 multiples of ", num, " are ", List)
11. swap first and last element of the list using inbuilt function [Link]()
List=[24, 27, 17, 10, 28]
print("Initial List:")
print(List)
first=[Link](0)
last=[Link](-1)
[Link](0,last)
[Link](first)
print("\nNew swaped List:")
print(List)
Practical Exam 3
12. #Program to add an element at specified index in a list
list = [10, 20, 30]
print (list)
[Link] (1, "ABC")
print (list)
[Link] (3, "PQR")
print (list)
[Link] (5, "XYZ")
print (list)
[Link] (len (list) -1, 99)
print (list)
13. WAP to sort the integer numbers,float and string in the list
num = [10, 30, 40, 20, 50]
[Link]()
print (num)
fnum = [10.23, 10.12, 20.45, 11.00, 0.1]
[Link]()
print (fnum)
str = ["Banana", "Cat", "Apple", "Dog", "Fish"]
[Link]()
print (str)
14. WAP to find the position of min and max elements of a list in Python
list = [10, 1, 2, 20, 3, 50]
min = [Link] (min(list)
max = [Link] (max(list))
print ("position of minimum element: ", min)
print ("position of maximum element: ", max)
15. to check whether the entered number is odd or even.
num=int(input("Enter any number "))
Practical Exam 4
rem=num%2
if num==0:
print("The number is",num)
elif rem==0:
print(num, "is an even number")
else:
print(num, "is an odd number")
16. print empty lists
l=[]
if len(l)==0:
print("list is empty")
else:
print("list is not empty")
17. maximum of the given 3 numbers
num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
num3=int(input("Enter the third number: "))
if(num1>num2 and num1>num3):
print(num1, "is maximum")
elif(num2>num1 and num2>num3):
print(num2, "is maximum")
else:
print(num3, "is maximum")
18. Calculator
menus
print("Calculator")
print("[Link]")
print("[Link]")
print("[Link]")
print("[Link]")
Practical Exam 5
input choice
ch=int(input("Enter Choice(1-4): "))
if ch==1:
a=int(input("Enter A:"))
b=int(input("Enter B:"))
c=a+b
print("Sum = ",c)
elif ch==2:
a=int(input("Enter A:"))
b=int(input("Enter B:"))
c=a-b
print("Difference = ",c)
elif ch==3:
a=int(input("Enter A:"))
b=int(input("Enter B:"))
c=a*b
print("Product = ",c)
elif ch==4:
a=int(input("Enter A:"))
b=int(input("Enter B:"))
c=a/b
print("Quotient = ",c)
else:
print("Invalid Choice")
19. import numpy and stats tools-manage packs
import numpy as np
a = [1,2,2,4,5,6]
print(" The mean of the list is", ([Link](a)))
print(" The median of the list is",([Link](a)))
import stats
m = [1,2,2,2,4,5,6,6]
x = [Link](m)
print(" The mode of the list is",x)
20. WAP to draw a linechart to find the unemployment rate
Practical Exam 6
import [Link] as plt
year = [1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990, 2000, 2010]
unemployment_rate = [9.8, 12, 8, 7.2, 6.9, 7, 6.5, 6.2, 5.5, 6.3]
[Link](year, unemployment_rate)
[Link]('unemployment rate vs year')
[Link]('year')
[Link]('unemployment rate')
[Link]()
21. WAP to display a scatter chart for the following points (2,5),(9,10),(8,3),(5,7),(6,18).
import [Link] as plt
x= [2,9,8,5,6]
y= [5,10,3,7,18]
[Link](x,y)
[Link]()
22. to display line chart from (2,5) to (9,10).
import [Link] as plt
x = [2,9]
y = [5,10]
[Link](x, y)
[Link]('X vs Y')
[Link]('X')
[Link]('Y')
[Link]()
23. WAP to Read csv file saved in your system and display its information
import csv
with open('[Link]') as file:
reader = [Link](file)
for row in reader:
print(row)
24. to identify the shape using Python
import cv3
image = [Link]('[Link]')
print("The shape of the image is",[Link])
Practical Exam 7
print("The size of the image is",[Link])
print("The data type of the image is",[Link])
25. to read an image and display using Python
from PIL import Image
#Read image
im = [Link]( '[Link]' )
#Display image
[Link]()
Practical Exam 8