Python All Pgs
Python All Pgs
Python All Pgs
print("***DISPLAYING DETAILS***\n")
print("Name: YASH KUMAR")
print("\nBranch: CSE 1")
print("\nRoll No.: 25207")
print("\nSubject: PYTHON ASSIGNMENT")
print("\nCollege: DRONACHARYA COLLEGE OF ENGINEERING")
print("\n***PROGRAM COMPLETED***")
PROGRAM-2
Snum_1=int(input("Enter A :"))
num_2=int(input("Enter B :"))
print("\n#SWAPPING USING THIRD VARIABLE#")
print("\nValue before swapping\n")
print("A=",num_1,"| B=",num_2)
var=num_1
num_1=num_2
num_2=var
print("\nValue after swapping\n")
print("A=",num_1,"| B=",num_2)
print("\n#SWAPPING USING COMMA OPERATOR#")
print("\nValue before swapping\n")
print("A=",num_1,"| B=",num_2)
num_1,num_2=num_2,num_1
print("\nValue after swapping\n")
print("A=",num_1,"| B=",num_2)
print("\n***PROGRAM COMPLETED***")
PROGRAM-3
while(num>0):
rev=num%10
add=add+rev
num=num//10
if(var%add==0):
print("\n",var,"is a HARSHAD number")
else:
print("\n",var,"is not a HARSHAD number")
print("\n***PROGRAM COMPLETED***")
PROGRAM-5
import math
print("\n#CHECKING FOR DISARIUM NUMBER#")
num=int(input("\nEnter the number: "))
pos=len(str(num))
var=num
add=0
while(num>0):
rem=num%10
add=add+math.pow(rem,pos)
pos=pos-1
num=num//10
if(var==add):
print("\n",var,"is a DISARIUM number")
else:
print("\n",var,"is NOT A DISARIUM number")
print("\n***PROGRAM COMPLETED***")
PROGRAM-6
l2=['Twenty','Thirty','Forty','Fifety','Sixety','Seventy','Eighty','Ninety']
if(digit==1 or int(num)<=19):
print("\n",l1[int(num)-1])
else:
for i in range(len(l2)):
if(i==(int(num[0]))-2):
print('\n',l2[i],end=" ")
print(l1[int(num[1])-1])
print("\n***PROGRAM COMPLETED***\n")
PROGRAM-7
hextobin_table={'0':'0000','1':'0001','2':'0010','3':'0011','4':'0000','5':'0101','6':'0110',
'7':'0111','8':'1000','9':'1001','A':'1010','B':'1011','C':'1100','D':'1101','E':'1110',
'F':'1111'}
binary=' '
print("\nBinary converted:",binary)
print("\n***PROGRAM COMLETED***")
PROGRAM-6
l2=['Twenty','Thirty','Forty','Fifety','Sixety','Seventy','Eighty','Ninety']
if(digit==1 or int(num)<=19):
print("\n",l1[int(num)-1])
else:
for i in range(len(l2)):
if(i==(int(num[0]))-2):
print('\n',l2[i],end=" ")
print(l1[int(num[1])-1])
print("\n***PROGRAM COMPLETED***\n")
PROGRAM-7
hextobin_table={'0':'0000','1':'0001','2':'0010','3':'0011','4':'0000','5':'0101','6':'0110',
'7':'0111','8':'1000','9':'1001','A':'1010','B':'1011','C':'1100','D':'1101','E':'1110',
'F':'1111'}
binary=' '
print("\nBinary converted:",binary)
print("\n***PROGRAM COMLETED***")
PROGRAM-8
print("\nInput Tuple:",t)
add=0
l=list(t)
for i in l:
add=add+int(i)
length=len(l)
avg=add/length
print("\n***PROGRAM COMPLETED***")
PROGRAM-9
def factorial(num):
if num<2:
return(1)
else:
return(num*factorial(num-1))
sumn=factorial(num)
print("\nFactorial of =",sumn)
print("\n***PROGRAM COMPLETED***")
PROGRAM-10
class heron():
def triangle(self,side1,side2,side3):
s=(side1+side2+side3)/2
self.area=math.sqrt(s*(s-side1)*(s-side2)*(s-side3))
def show(self):
print("\nArea of triangle=",self.area)
a=heron()
a.triangle(side1,side2,side3)
a.show()
PROGRAM-11
import tkinter as tk
# create a new tkinter window
window = tk.Tk()
window.title("Calculator")
class person:
def __init__(self, name, address, phone, Id):
self.name=name
self.address=address
self.phone=phone
self.Id=Id
class teacher(person):
def __init__(self,name, address, phone, Id,additional_TID,course,faculty):
super().__init__(name, address, phone, id)
self.additional_TID=additional_TID
self.course=course
self.faculty=faculty
class student(person):
def __init__(self,name, address, phone, Id,roll_no,course_enrolled):
super().__init__(name, address, phone, id)
self.roll_no=roll_no
self.course_enrolled=course_enrolled
p=person("Mia","H01",123,1)
t=teacher("Gia","H02",234,2,"T01","C01","Maths")
s=student("Ava","H03",345,3,69,"C02")
print(s.name)
print(t.name)
print(p.name)
PROGRAM-13
5 6 9 8 2
#TO DISPLAY BOX AND WHISKER PLOT FOR THE FOLLOWING DATA
matplotlib.pyplot as plt
data=[ 11, 11, 12, 12, 14, 16, 16, 16, 17, 18, 19, 21, 22, 21, 22, 24, 24, 24, 24, 24, 27, 27,
27, 26, 26, 26, 29, 29, 32, 34]
plt.show()
PROGRAM-14
#TO DISPLAY BOX AND WHISKER PLOT FOR THE FOLLOWING DATA
data=[3,7,8,5,12,14,21,13,18]
plt.boxplot(data)
plt.show()
PROGRAM-15
10). WRITE A PROGRAM TO DRAW A LINE PLOT AND BAR CHART FOR
FOLLOWINF DATA.
ELAPSED
0 1 2 3 4 5 6
TIME(s)
SPEED(m/s) 0 3 7 12 21 30 46.5
elapsed_time=[0,1,2,3,4,5,6]
speed=[0,3,6,7,14,21,46.5]
plt.plot(elapsed_time,speed)
plt.xlabel("ET")
plt.ylabel("SPEED")
plt.show()
ELAPSED
0 1 2 3 4 5 6
TIME(s)
SPEED(m/s) 0 3 7 12 21 30 46.5
elapsed_time=[0,1,2,3,4,5,6]
speed=[0,3,6,7,14,21,46.5]
plt.bar(elapsed_time,speed)
plt.xlabel("ET")
plt.ylabel("SPEED")
plt.show()