python practical exam sol
python practical exam sol
class py_solution:
print(py_solution().reverse_words('hello .py'))
2)Write a Python class named Student with two attributes student_name, marks.
Modify the attribute values of the said class and print the original and modified
class Student:
marks = 93
3)Write a python script to define the class person having members name, address.
Create a subclass called Employee with members staffed salary. Create 'n' objects of the
class Employee:
def__init__(self)
Class Person:
def__init__(self,name,address):
Self.name=name
self.address=address
Print("name of employee",self.name)
Print("address of employee",self.address)
Class emoticon(person)
def__init__(self,name,address,sal):
Super().__init__(name,address)
Self.sal=sal
super().Show data()
Print("salary",sal)
e1=emp(name,address,sal)
e1.showdata()
4)Write a Python script to generate and print a dictionary which contains a number
Sample Dictionary (n=5) Expected Output: {1:1, 2:4, 3:9, 4:16, 5:25}
for x in range(1,n+1):
d[x]=x*x
print(d)
5)Write a Python Program to Check if given number is prime or not. Also find
def fact(x):
f=1
i=1
While I<=x:
f=f*i
i=i+1
Print("factorial is ",f)
b=int(input("enter number"))
fact(b)
def prime(x)
i=2
b=x
flag=0
While(b<x)
If b%i==0:
flag=1
Break
Else:
i=i+1
Continue
if flag==0:
print("no prime")
else
print("not prime")
c=int(input("enter number"))
Prime(c)
Squares=lambda a:a*a
recarea=lambda b,c:b*c
Print("area of square",squarea)
Print("area of rectangle,recarea)
7)Write a Python program to accept two lists and merge the two lists into list of tuple.
l1=["amaze","kia","creta"]
l2=["honda","Suzuki","tata","Honda"]
Print("original is l1",l1)
Print("original is l2",l2)
l1.extend(l2)
Print("merged list",l1)
8).Write a Python program to input a positive integer. Display correct message for
while True:
try:
n = int(n)
break
except ValueError:
9)Write a Python function that accepts a string and calculate the number of upper case
def string_test(s):
d={"UPPER_CASE":0, "LOWER_CASE":0}
for c in s:
if c.isupper():
d["UPPER_CASE"]+=1
elif c.islower():
d["LOWER_CASE"]+=1
else:
pass
def fibonacci():
a=0
b=1
for i in range(6):
print(b)
a,b= b,a+b
obj = fibonacci()