0% found this document useful (0 votes)
22 views8 pages

Exp 14 15 16

The document describes three Python programming assignments. The first defines a class to print integer and character values in different orders. The second defines a class to calculate the area of squares and rectangles. The third defines a base class and two derived classes to represent different academic degrees.

Uploaded by

sangram.co10723
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views8 pages

Exp 14 15 16

The document describes three Python programming assignments. The first defines a class to print integer and character values in different orders. The second defines a class to calculate the area of squares and rectangles. The third defines a base class and two derived classes to represent different academic degrees.

Uploaded by

sangram.co10723
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Name-Sangram S Supalkar

TYCO-B 84

Experiment No. 14
Q. 1 Char Int
class PrintIntChar:

def show(self, i, c):


if type(i) == int:
print("Int :", i)
print("Char :", c)
else:
print("Char :", c)
print("Int :", i)

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:

def area(self, l, b=None):


if b is not None:
return l * b
else:
return l * l

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 setData(self, nm, dept, sal):


self.name = nm
self.department = dept
self.salary = sal

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

class Student(Persnal, Marks):

def getStud(self, r, n, c):


self.id = r
self.sname = n
self.city = c

def getMarks(self, m1, m2, m3, m4, m5):


self.m1 = m1
self.m2 = m2
self.m3 = m3
self.m4 = m4
self.m5 = m5
self.tol = m1 + m2 + m3 + m4 + m5
self.perc = self.tol / 5

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy