Python Lab Programs
Python Lab Programs
import math
n=eval(input("Enter the number : "))
print("Float Absolute value of ",n," is : ",math.fabs(n))
print("Ceil value of ",n," is : ",math.ceil(n))
print("Floor value of ",n," is : ",math.floor(n))
print("Exponential value of ",n," is : ",math.exp(n))
print("Log value of ",n," is : ",math.log(n))
print("Log value (Base10) of ",n," is : ",math.log10(n))
print("Sine value of ",n," is : ",math.sin(n))
print("Cosine value of ",n," is : ",math.cos(n))
print("Tangent value of ",n," is : ",math.tan(n))
print("Degrees value of ",n," is : ",math.degrees(n))
print("Radians value of ",n," is : ",math.radians(n))
print("Square root value of ",n," is : ",math.sqrt(n))
print("Percentage:",round(per,2))
print("Grade:",grade)
4. Program to generate prime numbers and calculate CPU time using time module.
print()
el=clock() - st
print("No. of Prime no.s : ",c)
print("Time elapsed : ",el, " seconds")
@decor
def accept():
n=input("Enter your phone number:")
return n;
7. Write a program to find sum of the array elements, largest array element and
smallest element in the array.
large=small=a[0]
for i in range(1,n):
if large<a[i]:
large=a[i]
if small>a[i]:
small=a[i]
9. Write a program to add name and scores of players into two separate lists and make
them into dictionary using zip function. Also retrieve runs by entering the player’s
name.
name=[]
score=[]
n=int(input("Enter How many players? "))
for i in range(0,n):
name.append(input("Enter Player name:"))
score.append(input("Enter score:"))
z=zip(name,score)
d=dict(z)
print(d)
name=input("Enter name of player for score: ")
print("The Score is",d[name])
10. Write a program to create class employee with instance variables eid, ename and
esalary. Accept and display n employees details.
class Employee:
def __init__(self,id,name,sal):
self.eid=id
self.ename=name
self.esal=sal
c=child("Lava","Rama","Dasharatha")
c.display1()
c.display2()
c.display3()
class Polygon(ABC):
@abstractmethod
def noofsides(self):
pass
class Triangle(Polygon):
def noofsides(self):
print("I have 3 sides")
class Pentagon(Polygon):
def noofsides(self):
print("I have 5 sides")
class Hexagon(Polygon):
def noofsides(self):
print("I have 6 sides")
class Rectangle(Polygon):
def noofsides(self):
print("I have 4 sides")
T = Triangle()
T.noofsides()
P = Pentagon()
P.noofsides()
H = Hexagon()
H.noofsides()
R=Rectangle()
R.noofsides()
class MyException(Exception):
def init (self, arg):
self.msg = arg
def check(dict):
for k,v in dict.items():
print ("Name=",k,"Balance=",v)
if v<2000.00:
raise MyException("Balance amount is less in the account of "+k)
n=int(input("Enter number of Customers:"))
bank={input("Enter Name:"):int(input("Enter Balance:")) for i in range(n)}
try:
check(bank)
except MyException as me:
print (me)
14. Write a program to find occurrence of each word and number of lines
present in a file.
def add_numbers():
res=int(e1.get())+int(e2.get())
label_text.set(res)
window = Tk()
label_text=StringVar();
Label(window, text="Enter First Number:").grid(row=0, sticky=W)
Label(window, text="Enter Second Number:").grid(row=1, sticky=W)
Label(window, text="Result of Addition:").grid(row=3, sticky=W)
result=Label(window, text="", textvariable=label_text).grid(row=3,column=1,
sticky=W)
e1 = Entry(window)
e2 = Entry(window)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)