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 list.pop()
List=[24, 27, 17, 10, 28]
print("Initial List:")
print(List)
first=List.pop(0)
last=List.pop(-1)
List.insert(0,last)
List.append(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)
list.insert (1, "ABC")
print (list)
list.insert (3, "PQR")
print (list)
list.insert (5, "XYZ")
print (list)
list.insert (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]
num.sort()
print (num)
fnum = [10.23, 10.12, 20.45, 11.00, 0.1]
fnum.sort()
print (fnum)
str = ["Banana", "Cat", "Apple", "Dog", "Fish"]
str.sort()
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 = list.index (min(list)
max = list.index (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("1.Add")
print("2.Substract")
print("3.Multiply")
print("4.Divide")
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", (np.mean(a)))
print(" The median of the list is",(np.median(a)))
import stats
m = [1,2,2,2,4,5,6,6]
x = stats.mode(m)
print(" The mode of the list is",x)
20. WAP to draw a linechart to find the unemployment rate
Practical Exam 6
import matplotlib.pyplot 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]
plt.plot(year, unemployment_rate)
plt.title('unemployment rate vs year')
plt.xlabel('year')
plt.ylabel('unemployment rate')
plt.show()
21. WAP to display a scatter chart for the following points (2,5),(9,10),(8,3),(5,7),(6,18).
import matplotlib.pyplot as plt
x= [2,9,8,5,6]
y= [5,10,3,7,18]
plt.scatter(x,y)
plt.show()
22. to display line chart from (2,5) to (9,10).
import matplotlib.pyplot as plt
x = [2,9]
y = [5,10]
plt.plot(x, y)
plt.title('X vs Y')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
23. WAP to Read csv file saved in your system and display its information
import csv
with open('marks.csv') as file:
reader = csv.reader(file)
for row in reader:
print(row)
24. to identify the shape using Python
import cv3
image = cv3.imread('bike.jpg')
print("The shape of the image is",image.shape)
Practical Exam 7
print("The size of the image is",image.size)
print("The data type of the image is",image.dtype)
25. to read an image and display using Python
from PIL import Image
#Read image
im = Image.open( 'bike.jpg' )
#Display image
im.show()
Practical Exam 8