Exp 14 15 16
Exp 14 15 16
TYCO-B 84
Experiment No. 14
Q. 1 Char Int
class PrintIntChar:
ob1 = PrintIntChar()
ob1.show(10, 'H')
ob1.show("C", 23)
Output
Int : 10
Char : H
Char : 23
Int : C
Q. 2 Class Area
class Area:
a = Area()
print("Area of Square :", a.area(4))
print("Area of rectangle :", a.area(5, 4))
Output
Area of Square : 16
Area of rectangle : 20
Name-Sangram S Supalkar
TYCO-B 84
Q. 3 Class Degree
class Degree:
def getDegree(self):
print("I got a Degree")
class Undergraduate(Degree):
def showedu(self):
print("I am an Undergraduate")
class Postgraduate(Degree):
def showedu(self):
print("I am an Postgraduate")
d = Degree()
u = Undergraduate()
p = Postgraduate()
d.getDegree()
u.showedu()
p.showedu()
Output
I got a Degree
I am an Undergraduate
I am an Postgraduate
Name-Sangram S Supalkar
TYCO-B 84
Experiment No. 15
Q. 2 Simple Inheritance
class Data:
roll = 0
name = city = ""
def getStud(self, roll, nm, city):
self.name = nm
self.roll = roll
self.city = city
class Student(Data):
def showStud(self):
print("Roll No :", self.roll)
print("Name :", self.name)
print("City :", self.city)
print("Student 1")
stud1 = Student()
stud1.getStud(1, "ABC", "XYZ")
stud1.showStud()
print("\nStudent 2")
stud2 = Student()
stud2.getStud(2, "PQR", "XYZ")
stud2.showStud()
Output
Student 1
Roll No : 1
Name : ABC
City : XYZ
Student 2
Roll No : 2
Name : PQR
City : XYZ
Q. 1 Employee
class Employee:
name = department = ""
salary = 0
def showdata(self):
print("\nEmployee Details")
print("Name :", self.name)
print("Department :", self.department)
print("Salary :", self.salary)
Name-Sangram S Supalkar
TYCO-B 84
e = Employee()
e.setData("ABC", "CO", 10000)
e.showdata()
Output
Employee Details
Name : ABC
Department : CO
Salary : 10000
Q. 3 Multiple Inheritance
class Persnal:
id = 0
sname = city = ""
class Marks:
m1 = m2 = m3 = m4 = m5 = tol = perc = 0
def displayData(self):
print("Student Information")
print("Roll No :", self.id)
print("Name :", self.sname)
print("CIty :", self.city)
print("Total Marks :", self.tol)
print("Percentage :", self.perc, "%")
s1 = Student()
s1.getStud(1, "ABC", "Sangli")
s1.getMarks(60, 47, 86, 98, 76)
s1.displayData()
Name-Sangram S Supalkar
TYCO-B 84
Output
Student Information
Roll No : 1
Name : ABC
CIty : Sangli
Total Marks : 367
Percentage : 73.4 %
Name-Sangram S Supalkar
TYCO-B 84
Experiment No. 16
Q. 2 Password Validation
class Error(ArithmeticError):
pass
class CharException(Error):
pass
class SymbolException(Error):
pass
class OtherSymbolException(Error):
pass
class DigitException(Error):
pass
class LowerCharException(Error):
pass
class UpperCharException(Error):
pass
def checknum(p):
num = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
isnum = True
for i in p:
if i in num:
isnum = False
return isnum
def checksymbol(p):
sym = ['@', '-', '_']
issym = True
for i in p:
if i in sym:
issym = False
return issym
def checkothersymbol(p):
sym = ['@', '-', '_']
issym = True
for i in p:
if i in sym:
issym = False
return issym
def checklowercase(p):
islower = True
for i in p:
if i.islower():
return False
return islower
Name-Sangram S Supalkar
TYCO-B 84
def checkuppercase(p):
isupper = True
for i in p:
if i.isupper():
return False
return isupper
while True:
try:
p = input("Enter Your Password : ")
if len(p) < 8:
raise CharException
elif checkothersymbol(p):
raise OtherSymbolException
elif checksymbol(p):
raise SymbolException
elif checknum(p):
raise DigitException
elif checklowercase(p):
raise LowerCharException
elif checkuppercase(p):
raise UpperCharException
else:
print("Password is Valid")
break
except CharException:
print("DigitException : Password should contain 8 charactors")
except OtherSymbolException:
print("OtherSymbolException : Password should only contain '@','-','_'
symbols")
except SymbolException:
print("SymbolException : Password should contain One Symbol")
except DigitException:
print("DigitException : Password should contain One Digit")
except LowerCharException:
print("LowerCharException : Password should contain at least one
lowercase letter")
except UpperCharException:
print("UpperCharException : Password should contain at least one
uppercase letter")
Name-Sangram S Supalkar
TYCO-B 84
Output
Enter Your Password : admin
DigitException : Password should contain 8 charactors
Enter Your Password : admin@admin
DigitException : Password should contain One Digit
Enter Your Password : admin123
SymbolException : Password should contain One Symbol
Enter Your Password : admin#123
OtherSymbolException : Password should only contain '@','-','_' symbols
Enter Your Password : admin@123
UpperCharException : Password should contain at least one uppercase letter
Enter Your Password : Admin@123
Password is Valid
Q. 1 ZeroDivisionError
n1 = int(input("Enter num 1 : "))
n2 = int(input("Enter num 2 : "))
try:
div = n1 / n2
except ZeroDivisionError:
print(n1, "can not divide by Zero")
else:
print("Division : ", div)
Output
Enter num 1 : 5
Enter num 2 : 0
5 can not divide by Zero