Practical File (Final)
Practical File (Final)
No:1
AREA OF THE CIRCLE
12/08/2022
AIM:
To print the Area of Circle
CODING:
r = float(input("Enter the radius of the circle :"))
ac = 3.14*(r**2)
OUTPUT:
1
Pgm.No:2
GENARATING A THREE DIGIT NUMBER
18/08/2022
AIM:
Print a 3 digit number created as <n(n+1)(n+2)>
CODING:
n = int(input("Enter a single digit value"))
a = n+1
b = n+2
x = n*100+a*10+b
print (x)
OUTPUT:
2
Pgm.No:3
SWAP NUMBERS BY THERE SUMS
24/08/2022
AIM:
Read Three Variables and Swap First Two Variables
CODING:
x = int(input("Enter x value :"))
y = int(input("Enter y value :"))
z = int(input("Enter z value :"))
x=y
y=z
z=x
print ('x -',x,'y -',y,'z -',z)
OUTPUT:
3
Pgm.No:4
CONVERTION OF TEMPERTURE
05/09/2022
AIM:
Convert the degree Celcius to degree Fahrenheit
CODING:
bp_c = 100
fp_c = 0
bp_f = (bp_c*(9/5))+32
fp_f = (fp_c*(9/5))+32
OUTPUT:
4
Pgm.No:5
ENERGY CONVERTION
10/09/2022
AIM:
Converting the Mass into Equivalent Energy
CODING:
import math
m = float(input("Enter mass: "))
c =3*pow(10,8)
E = m*(c*c)
print("Equivalent Energy: ", E,"Joule")
OUTPUT:
5
Pgm.No:6
TIME CALCULATOR
13/09/2021
AIM:
Read the number in Seconds and Convert into Minutes
CODING:
year = float(input("Enter how much year: "))
d = year*365
h = d*24
m = h*60
s = m*60
print (year,"years is: ")
print (d,"Days")
print (h,"Hours")
print (m,"Minutes")
print (s,"Seconds")
OUTPUT:
6
Pgm.No:7
TIME CONVERTION
15/09/2022
AIM:
Read the number in Seconds and Convert into Minutes
CODING:
n = int(input("Enter the seconds: "))
m = n//60
s = n%60
print (m,"minutes",s,"seconds")
OUTPUT:
7
Pgm.No:8 GENERATING RANDOM NUMBERS BETWEEN
THE GIVEN RANGE
17/09/2022
AIM:
Print Random Numbers Between the Given Range
CODING:
import random
print (random.randint(100,999)//5)
print (random.randint(100,999)//5)
print (random.randint(100,999)//5)
OUTPUT:
8
Pgm.No:9
GENERATE 6 DIGIT OTP
12/10/2022
AIM:
Print 6 digit radom secure OTP
CODING:
import random
print(random.randint(100000,999999))
OUTPUT:
9
Pgm.No:10 MEAN, MEDIAN and MODE
18/10/2022
AIM:
Finding and Print the Mean, Median and Mode
CODING:
import random
import statistics
C = []
s=0
d=1
while (d<=6):
d = d+1
n1 = random.randrange(1,99,3)
C.append(n1)
print(C)
I = statistics.mean(C)
J = statistics.median(C)
K = statistics.mode(C)
print ("Mean :",I, "Median :",J, "Mode :",K)
10
OUTPUT:
11
Pgm.No:11
PROPERTIES OF SQUARE AND CUBE
20/10/2021
AIM:
Finding the properties of square and cube
CODING:
a = int(input("Enter a value: " ))
area=p=TSA=V=0
print ("1.Area of Square ")
print ("2.Perimetre of Square ")
print ("3.Total Surface Area of Cube ")
print ("4.Volume of Cube ")
ch = int(input("Enter the number above which you want: "))
if ch==1 :
area = a**2
print("Area of Square:",area)
elif ch==2 :
p = 4*a
print("Perimetre of Square:",p)
elif ch==3 :
TSA = 6*(a**2)
print("Total Surface Area of Cube:",TSA)
elif ch==4 :
12
V = a**3
print("Volume of Cube:",V)
else :
print ("Invalid number",a)
OUTPUT:
13
Pgm.No:12
SUM OF SERIES
26/10/2021
AIM:
Finding the sum of series of 1 + 1/8+1/27.....1/n**3
CODING:
n = int(input("Enter limit (n):"))
ssum = 0
print("1",end=" ")
ssum += 1
for i in range(2, (n+1)):
icube = (i*i*i)
term = 1/icube
ssum += term
print("+1/",icube,end=" ")
print ("=",ssum)
OUTPUT:
14
Pgm.No:13 ROOTES OF A QUADRATIC EQUATION
03/11/2021
AIM:
Reading and Finding the roots of a Quadratic Equation
CODING:
import math
print ("For quadratic equation, ax**2+bx+c = 0,enter
coefficients below")
a = int(input("Enter a :"))
b = int(input("Enter b :"))
c = int(input("Enter c :"))
if a == 0:
print ("Value of",a, "should not be zero")
print ("\n Aborting !!!!!")
else :
delta = b*b-4*a*c
if delta > 0 :
root1 = (-b+math.sqrt(delta))/(2*a)
root2 = (-b-math.sqrt(delta))/(2*a)
print ("Roots are REAL and UNEQUAL")
print ("Root1 =",root1,",Root2 =",root2)
15
elif delta == 0 :
root1 = -b/(2*a) ;
print ("Roots are REAL and EQUAL")
print ("Root1 =",root1,",Root2 =",root1)
else :
print ("Roots are COMPLEX and IMAGINARY")
OUTPUT:
16
Pgm.No:14
SUM OF FACTORIAL SERIES
05/11/2021
AIM:
Finding the Sum of Factorial Series
CODING:
import math
x = int(input("Enter the number for x"))
n = int(input("Enter the number for n"))
s=1
for i in range(1,n+1):
s+=x**i/math.factorial(i)
print(s)
OUTPUT:
17
Pgm.No:15
NUMBER TRIANGLE
15/11/2022
AIM:
Print the number in Triangle
CODING:
n=4
s = n*2-1
for i in range(1 , n+1) :
for j in range(0,s) :
print (end = " ")
for j in range(i,0,-1) :
print (j,end = " ")
for j in range(2,i+1) :
print (j,end = " ")
s = s-2
print()
OUTPUT:
18
Pgm.No:16
ASTRIC PATTERNS
18/11/2022
AIM:
Designing with Astric in different Patterns
CODING:
a)
n=3
for i in range(n) :
for j in range(n, i+1, -1) :
print(' ', end = '')
for k in range(i+1) :
print('*', end = ' ')
print()
for i in range(n-1) :
for j in range(i + 1) :
print(' ', end = '')
for k in range(n-1, i, -1) :
print('*', end = ' ')
print()
b)
19
for i in range (1,4):
for j in range (1,i+1) :
print ("x",end='')
print ()
c)
n=3
for i in range(1, n+1) :
for j in range(n, i, -1) :
print(' ', end = '')
x=1
while x < 2 * i :
if x == 1 or x == 2 * i - 1 :
20
print('*', end = '')
else :
print(' ', end = '')
x += 1
print()
x=1
while x < 2 * i :
if x == 1 or x == 2 * i - 1 :
print('*', end = '')
else :
print(' ', end = '')
x += 1
print()
d)
n=4
for i in range(1, n+1) :
x=1
while x < 2 * i :
21
if x == 1 or x == 2 * i - 1 :
print('*', end = '')
else :
print(' ', end = '')
x += 1
print()
22
OUTPUT:
a)
b)
C)
d)
23
Pgm.No:17
CHARACTER CALCULUS
22/11/2022
AIM:
Finding number of upper, lower letters, digits, alphabets and
symbols
CODING:
l = input("Enter a line:")
lc = uc = 0
dc = ac = symc = 0
for a in l :
if a.islower():
lc+=1
if a.isupper():
uc+=1
if a.isdigit():
dc+=1
if a.isalpha():
ac+=1
if a.isalnum()!=True and a != ' ':
symc+=1
print("Number of uppercase letters :", uc)
print("Number of lowercase letters :", lc)
24
print("Number of alphabets :", ac)
print("Number of digits :", dc)
print("Number of symbols :", symc)
OUTPUT:
25
Pgm.No:18
ALPHA NUMERIC
25/11/2022
AIM:
Print the number of character and word, Even find
percentage of alphanumeric
CODING:
w = input("Enter the alphanumeric sentence:")
a = w.split()
symc=0
for b in w:
if b.isalnum():
symc+=1
c = (symc/len(w))*100
print("Number of characters:",len(w))
print("Number of words:",len(a))
print("Percentage of alphanumeric:",c,"%")
OUTPUT:
26
Pgm.No:19
LIST MANIPULATION
29/11/2022
AIM:
Using the List Functions in a program
CODING:
val = [17,23,18,19]
print("The list is: ",val)
while True :
print("?Main Menu")
print("1.Insert")
print("2.Delete")
print("3.Exit")
ch = int(input("Enter your choice 1/2/3:"))
if ch==1:
item = int(input("Enter item"))
pos = int(input("Insert at which position?"))
index = pos-1
val.insert(index,item)
print("Success! list now is :",val)
elif ch==2:
print("Deletion Menu")
print("1.Delete using Value")
27
print("2.Delete using index")
print("3.Delete using sublist")
dch = int(input("Enter choice(1 or 2 or 3):"))
if dch ==1:
item = int(input("Enter item to be deleted"))
val.remove(item)
print("list now is :",val)
elif dch ==2:
index = int(input("Enter index of item to be deleted:"))
val.pop(index)
print("List now is:",val)
elif dch ==3:
l =int(input("Enter lower limit of list slice to be
deleted:"))
h = int(input("Enter upper limit of list slice to be
deleted:"))
del val[l:h]
print("List now is :",val)
else :
print("valid choices are 1/2/3 only.")
if ch ==3:
break;
else :
print("valid choices are 1/2/3 only.")
28
OUTPUT:
29
Pgm.No:20
LIST ELEMENT FREQUENCY
30/11/2022
AIM:
Print Unique and duplicate Elements with Finding Frequency
CODING:
lst=eval(input("Enter list:"))
length = len(lst)
uniq=[]
dupl=[]
count = i = 0
while i < length :
element = lst[i]
count = 1
if element not in uniq and element not in dupl:
i+=1
for j in range(i,length):
if element ==lst[j]:
count+=1
else :
print("Element",element,"frequency:",count)
if count ==1:
uniq.append(element)
30
else:
dupl.append(element)
else:
i+=1
print("Original list",lst)
print("Unique elements list",uniq)
print("Duplicates elements list",dupl)
OUTPUT:
31
Pgm.No:21
CONSOLIDATED MEMO USING TUPLE
02/12/2022
AIM:
To write a python program to create student data list and
gentator a malit list from the data
CODING:
n =int(input("Enter the no.of students"))
tup=()
while True:
print("Main Menu")
print("1.Accept")
print("2.Display")
print("3.Search")
print("4.Merit List")
print("5.Exit")
ch=int(input ("Enter your choice:"))
if ch==1:
lst1=[]
for i in range (0,n):
lst=[]
tup=eval(input("Enter the name of student, total
marks for 500, average"))
lst.extend(tup)
32
print(lst)
avg=lst[1]/5
lst.append(avg)
if lst[2]>32:
lst.append("Pass")
else:
lst.append("Fail")
lst1.append(tuple(lst))
tup=tuple(lst1)
print(tup)
if ch==2:
for i in range(len(tup)):
print(tup[i][0],'\t',tup[i][1],'\t',tup[i][2],'\t',tup[i][3])
if ch==3:
s=0
name=input("Enter the Name of the student:")
for i in range(len(tup)):
if tup[i][0]==name:
print(tup[i])
s=1
else:
if s==0:
print("Name not found")
if ch==4:
33
ml=[]
for i in range(len(tup)):
if tup[i][2]>75:
ml.append(tup[i][0])
print("Merit list:",tuple(ml))
if ch==5:
break
else:
print("Enter the correct choice")
OUTPUT:
34
35
Pgm.No:22
SORTING STATUS
07/12/2022
AIM:
Finding the elements of tuple is First half sorted or not
sorted
CODING:
tup = eval(input("Enter a tuple:"))
In = len(tup)
mid = In//2
if In%2 ==1:
mid = mid+1
half = tup[:mid]
if sorted(half) == list(tup[:mid]):
print("First half is sorted")
else :
print("First half is not sorted")
OUTPUT:
36
Pgm.No:23
STUDENT’S DISTINCTION LIST
13/12/2022
AIM:
Accepting the Students details and print the Students details
whom are more than 75
CODING:
n = int(input("How many Students?"))
stu={}
for i in range(1,n+1):
print("Enter details of Student",(i))
rollno = int(input("Roll number:"))
name = input("Name:")
marks = float(input("Marks :"))
d ={"Roll_no" : rollno,"Name" : name,"Marks" : marks}
key ="Stu"+str(i)
stu[key] = d
print("Students with marks > 75 are:")
for i in range(1,n+1):
key = "Stu" + str(i)
if stu[key]["Marks"] >=75:
print(stu[key])
37
OUTPUT:
38
Pgm.No:24
ALPHABET FREQUENCY
16/12/2022
AIM:
Reading the Sentence and converts into dictionary
CODING:
sen = input("Enter a sentence:")
sen = sen.lower()
ad = 'abcdefghijklmnopqrstuvwxyz0123456789'
char_count={}
print("Total characters in the sentence are:",len(sen))
for char in sen :
if char in ad :
if char in char_count:
char_count[char] = char_count[char]+1
else :
char_count[char] = 1
print(char_count)
OUTPUT:
39
Pgm.No:25
PHONE DIRECTORY
20/12/2022
AIM:
To write a python program to create Contact list as Phone
Directory
CODING:
n=int(input("How many friends?"))
fd={}
for i in range(n):
print("Enter details of friend",(i+1))
name=input("Name:")
ph=int(input("Phone:"))
fd[name]=ph
print("Friends dictionary is",fd)
ch=0
while ch!=7:
print("\tMenu")
print("1,Display all friends")
print("2.Add new friend")
print("3.Delete a friend")
print("4.Modify a phone number")
print("5.Search for a friend")
print("6.Sort on names")
40
print("7.Exit")
ch=int(input("Enter your choice(1..7) :"))
if ch==1:
print(fd)
elif ch==2:
print("Enter details of new friend")
name=input("Name:")
ph=int(input("Phone:"))
fd[name]=ph
elif ch==3:
nm=input("Friend Name to be deleted:")
res=fd.pop(nm,-1)
if res!=-1:
print(res,"Deleted")
else:
print("No such friend")
elif ch==4:
name=input("Friend Name:")
ph=int(input("changed phone:"))
fd[name]=ph
elif ch==5:
name=input("Friend Name:")
if name in fd:
print(name,"exsist in the dictionary.")
41
else:
print(name,"does not exsist in the dictionary.")
elif ch==6:
lst=sorted(fd)
print("{",end="")
for a in lst:
print(a,":",fd[a],end="")
print("}")
elif ch==7:
break
else:
print("Valid coices are 1..")
42
OUTPUT:
43
44