You are on page 1of 43

Pgm.no.

1 AREA OF CIRCLE
12/8/22

AIM:
To get area of circle through radius

CODING:
r=int(input(“Enter the value of radius:”))
a=3.14*r*r
print("Area of circle:" ,a)

OUTPUT:

1|Page
Pgm.No 2 GENERATING A THREE DIGIT NUMBER
18/8/22

AIM:
To create a three digit number with a input single digit
number

CODING:
n=int(input("Enter the value of n:"))
a=n*100
b=(n+1)*10
c=n+2
s=a+b+c
print("Three Digit value:",s)

OUTPUT:

2|Page
Pgm.No3
Swaping Numbers By Their Sums
24/8/22

AIM:
To read three numbers in three variables and swap first two
variables with the sum of first and second

CODING:
a=int(input("Enter the value of a:"))
b=int(input("Enter the value of b:"))
c=int(input("Enter the value of c:"))
a=a+b
b=b+c
c=c+a
print("a:",a,"b:",b,"c:",c)

OUTPUT:

3|Page
Pgm.No 4 CONVERSION OF TEMPERATURE
05/9/22

AIM:
Temperature Conversion from Celsius to Fahrenheit in
boiling point 100 and freezing point 0.

CODING:
bp_in_c=100
fp_in_c=0
bp_in_f=(bp_in_c*9/5)+32
fp_in_f=(fp_in_c*9/5)+32
print("Boiling point in Celcius is",bp_in_c,"and in
Fahrenheit",bp_in_f)
print("Freezing point in Celcius is",fp_in_c,"and in
Fahrenheit",fp_in_f)

OUTPUT:

4|Page
Pgm.No 5 ENERGY CONVERSION
10/9/22

AIM:
To determine the energy of an object by its mass.

CODING:
import math
m=float(input("Enter mass:"))
c=3*pow(10,8)
E=m*c*c
print("Equivalent energy;",E,"Joule")

OUTPUT:

5|Page
Pgm.No6 CALCULATING THE NUMBER OF
13/9/22 DAYS,HOURS,MINUTES AND SECONDS

AIM:
Calculating the Number of Days, Hours, Minutes and
Seconds.

CODING:
y=float(input("How many years?"))
d=y*365
h=d*24
m=h*60
s=m*60
print(y, "years is:")
print(d, "days")
print(h,"hours")
print(m,"minutes")
print(s,"seconds")

OUTPUT:

6|Page
Pgm.No7 TIME CONVERSION
15/9/22

AIM:
To input seconds and convert it to minutes and seconds

CODING:
sec=int(input("number of second:"))
m=sec//30
s=sec%60
print(sec,"second is equal to",m,"minutes and",s,"second")

OUTPUT:

7|Page
Pgm.No8 GENERATING RANDOM NUMBERS BETWEEN
THE GIVEN RANGE
17/9/22

AIM:
To generate three random integers between 100 And 999
which is divisible by 5.

CODING:
import random
a =random.randrange(100000,999999)
print("OTP:",a)

OUTPUT:

8|Page
Pgm.No9 GENERATING 6 DIGIT OTP
12/10/22

AIM:
To Generate 6 Digit Random Secure OTP between 100000
and 999999.

CODING:
import random
a =random.randrange(100000,999999)
print("OTP:",a)

OUTPUT:

9|Page
Pgm.No10 MEAN, MEDIAN AND MODE
18/10/22

AIM:
To print the mean, median and mode of the generated 6
numbers.
CODING:
import random
import statistics
a=random.randrange(5,60,5)
b=random.randrange(5,60,5)
c=random.randrange(5,60,5)
d=random.randrange(5,60,5)
e=random.randrange(5,60,5)
f=random.randrange(5,60,5)
g=a,b,c,d,e,f
print(" Six random numbers:",a,b,c,d,e,f)
print("Mean",statistics.mean(g))
print("Median",statistics.median(g))
print("Mode",statistics.mode(g))

OUTPUT:

10 | P a g e
Pgm.No11 PROPERTIES OF SQUARE AND CUBE
20/10/22

AIM:
To display a menu for calculating properties of square and
cube.
CODING:
a=int(input("Enter the value of a:"))
print("1.Area of a square:")
print("2.Perimeter of a square:")
print("3.Volume of a cube:")
print("4.Total Surface Area:")
ch=int(input("Menu Number:"))
if ch==1:
area=a*a
print("Area of a square:",area)
elif ch==2:
perimeter=4*a
print("Perimeter of a square:",perimeter)
elif ch==3:
volume=a**3
print("Volume of a cube:",volume)
else:
TSA=6*(a*2)
print("Total Surface Area:",TSA)

11 | P a g e
OUTPUT:

12 | P a g e
Pgm.No12 SUM OF SERIES
26/10/22

AIM:
To find the sum of series where the number n is the input by
the user.

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:

13 | P a g e
Pgm.No13 ROOTS OF A QUADRATIC EQUATION
3/11/22

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)
elif delta ==0:
root1 = -b/(2*a) ;

14 | P a g e
print ("Roots are REAL and EQUAL")
print ("Root1 =",root1,",Root2 =",root1)
else :
print ("Roots are COMPLEX and
IMAGINARY")

OUTPUT:

15 | P a g e
Pgm.No14 SUM OF FACTORIAL SERIES
5/11/22

AIM:
To find the sum of factorial series where the number n is the
input by the user

CODING:
n = int(input("Enter The Power Value:"))
x = int(input("Enter The Base Value:"))
import math
def factorial(x):
return math.factorial(x)
s=1
for i in range (1,n+1):
s =s+( x**i/factorial(i))
print ("Sum =",s)

OUTPUT:

16 | P a g e
Pgm.No15 NUMBER TRIANGLE
15/11/22

AIM:
To print the number triangle
CODING:
n=5
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:

17 | P a g e
Pgm.No16 ASTRICK PATTERN
18/11/22

AIM:
To create a astrick pattern
CODING:
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()

OUTPUT:

18 | P a g e
Pgm.No17 CHARACTER CALCULUS
22/11/22

AIM:
To find number of uppercase letters,lowercase,letters
alphabets,digits and symbols.
CODING:
line=input("Enter a line:")
lowercount = uppercount = 0
digitcount = alphacount = symcount = 0
for a in line :
if a.islower() :
lowercount +=1
if a.isupper() :
uppercount +=1
if a.isdigit() :
digitcount +=1
if a.isalpha() :
alphacount +=1
if a.isalnum ( ) !=True and a!=' ':
symcount+=1

19 | P a g e
print("Number of uppercase letters :",uppercount)
print("Number of lowercase letters :",lowercount)
print("Number of alphabets :",alphacount)
print("Number of digits :",digitcount)
print("Number of symbols :",symcount)
OUTPUT:

20 | P a g e
21 | P a g e
Pgm.No18 ALPHA NUMERIC
25/11/22

AIM:
To find number of words,characters present in the sentence
and to find the percentage of alpha numeric characters in
the sentences.

CODING:
c = input("Enter a sentence")
n= c.split(" ")
g= len(n)
print("the number of words are:",g)
x = len(c)
print("The number of characters are: ", x)
aphanum=0
for i in c:
if i.isalnum():
aphanum+=1
print("The number of alphanumeric characters
are:",aphanum)
per = (
aphanum*100)/x
print( "the percentage of alphanumerics are:",per)

22 | P a g e
OUTPUT:

23 | P a g e
Pgm.No19 LIST MANIPULATION
29/11/22

AIM:
To write a program that display options for inserting or
deleting elements in a list

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("Sucess! List now is:", val)
elif ch == 2:
print(" Deletion Menu")
print("1. Delete using value")

24 | P a g e
print("2. Delete using index")
print("3. Delete a 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 the index of item to be
deleted :"))
val.pop(index)
print("List now is :",val)
elif dch == 3 :
l=int(input("enter the lower limit of list slice to be
deleted:"))
h=int(input("enter the 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.")

25 | P a g e
OUTPUT:

26 | P a g e
Pgm.No20 LIST ELEMENT FREQUENCY
30/11/22

AIM:
To find the frequencies of the element in the list and also to
print unique and duplicate elements.

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)

27 | P a g e
else:
dupl.append(element)
else:
i+=1

print("Orginal list",list)
print("Unique list", uniq)
print("Duplicates element list", dupl)

OUTPUT:

28 | P a g e
Pgm.No21 CONSOLIDATED MEMO USING TUPLES
2/12/22

AIM:
To write a python program to create student data list and
generate and a merit list from from the existing one.
CODING:
lst=[]
n=int(input("Enter number of students: "))
while True:
print("1)Accept")
print("2)Display")
print("3)Search")
print("4)Merit List")
print("5)Exit")
ch=int(input(" Enter your choice 1/2/3/4/5: "))
if ch == 1:
for i in range(n):
name= input("Enter name of the student: ")
tm = int(input("Enter total marks of the student: "))
avg= tm/5
if avg > 33:
res= "Pass"
else:
res="Fail"

29 | P a g e
l1=(name,tm,avg,res)
print(l1)
lst.append(l1)
if ch == 2:
print("The list of all students, their total marks, and
their average as below: ")
print(tuple(lst))
if ch == 3:
s=0
name = input("Enter a students name")
for i in (lst):
if i[0] == name:
print(i)
s=1
if s==0 :
print("The student does not exist!!")
if ch == 4:
print("The merit list of students are: ")
lst1=[]
for i in (lst):
if i[2]>75:
lst1.append(i[0])
print(tuple(lst1))
if ch == 5:
break

30 | P a g e
OUTPUT:

31 | P a g e
32 | P a g e
Pgm.No22 SORTING STATUS
7/11/22

AIM:
To create a program to check in the first half of the tuple are
sorted in ascending order or not.

CODING:
tup=eval(input("enter a tuple:"))
ln=len(tup)
mid=ln//2
if ln%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:

33 | P a g e
Pgm.No23 STUDENT’S DISTINCTION LIST
13/12/22

AIM:
To create a program to create a dictionary with the roll
number, name and marks of n students in a class and
display the names of students who have marks above 75.

CODING:
n=int(input("How many students?"))
stu={}
for i in range(1,n+1):
print("Enter the details of the 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])

34 | P a g e
OUTPUT:

35 | P a g e
Pgm.No24 ALPHABET FREQUENCY
16/12/22

AIM:
To create a program to read a sentence and then create a
dictionary contains the frequency of letters and digits in the
sentence.(Ignoring symbols).

CODING:
sen=input("enter a sentence:")
sen=sen.lower()
alphabet_digits='abcdefghifklmnoprstuvwxyz0123456789'
char_count={}
print("Total characters in the sentences are:",len(sen))
for char in sen:
if char in alphabet_digits:
if char in char_count :
char_count[char]=char_count[char]+1
else:
char_count[char]=1
print(char_count)

OUTPUT:

36 | P a g e
Pgm.No25 PHONE DIRECTORY
20/12/22

AIM:
To create a program that input our friends’ names and their
Phone numbers and store them in the dictionary as key
value pair.

CODING:
n=int(input("How many friends?"))
fd={}
for i in range(n):
print("Enter details of friends", (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")

37 | P a g e
print("7.Exit")
ch=int(input("Enter your choice (1..7) :"))
if ch ==1:
print(fd)
elif ch ==2:
print("Enter details of new friends")
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,"exist in the dictionary.")

38 | P a g e
else:
print(name,"does not exists in the dictionary.")
elif ch==6:
lst=sorted(fd)
print("{",end="")
for a in lst:
print(a,":",fd[a],end="")
print("}")
if ch==7:
break
else:
print("valid choices are 1..")

39 | P a g e
OUTPUT:

40 | P a g e
41 | P a g e
42 | P a g e
43 | P a g e

You might also like