Professional Documents
Culture Documents
E017 - JaidenDsouza - CSPractical6.ipynb - Colaboratory
E017 - JaidenDsouza - CSPractical6.ipynb - Colaboratory
ipynb - Colaboratory
TASK 1 Q1
class test:
def __init__(self, a="hello world"):
self.a = a
def display(self):
print(self.a)
obj = test()
obj.display()
hello world
TASK 1 Q2
class change:
def __init__(self, x, y, z):
self.a = x+y+z
x = change(1,2,3)
y = getattr(x,'a')
setattr(x,'a',y+1)
print(x.a)
TASK 1 Q3
class fruits:
def __init__(self,price):
self.price = price
obj = fruits(50)
obj.quantity = 10
obj.bags = 2
print(obj.quantity + len(obj.__dict__))
13
TASK 2 Q1
suitList = ["Spades", "Hearts", "Clubs", "Diamonds"]
valDict = {1:"Ace", 2:"Two", 3:"Three", 4:"Four", 5:"Five", 6:"Six", 7:"Seven", 8:"
class cards:
def __init__(self, suit, value):
self.suit = suit
self.value = value
def display(self,valDict):
https://colab.research.google.com/drive/1r15kWbohFp_MiI7Hi8k5fvco6_3Ac6Cn#scrollTo=NdUunLs-vaYb&printMode=true 1/5
9/10/22, 5:34 PM E017_JaidenDsouza_CSPractical6.ipynb - Colaboratory
print(valDict[self.value], " of ", self.suit)
val = int(input("enter card number: "))
while val not in range(1,14):
print("invalid card number")
val = int(input("enter card number: "))
s = input("enter suit of card: ")
s = s.capitalize()
while s not in suitList:
s = input("enter suit of card: ")
s = s.capitalize()
obj = cards(s,val)
obj.display(valDict)
Ace of Spades
TASK 2 Q2
class employee:
def __init__(self, name, desig, telno):
self.name = name
self.desig = desig
self.telno = telno
def display(self, emplist):
count=0
for i in range(0,3):
if len(empList[i].name) > 3:
print("NAME: ",empList[i].name)
print("DESIGNATION: ",empList[i].desig)
print("TELEPHONE NUMBER: ",empList[i].telno)
count += 1
print("number of valid employees: ",count)
empList=[]
for i in range (0,3):
name = input("enter name: ")
desig = input("enter designation: ")
telno = input("enter phone number: ")
obj = employee(name,desig,telno)
empList.append(obj)
obj1 = employee("","","")
obj1.display(empList)
https://colab.research.google.com/drive/1r15kWbohFp_MiI7Hi8k5fvco6_3Ac6Cn#scrollTo=NdUunLs-vaYb&printMode=true 2/5
9/10/22, 5:34 PM E017_JaidenDsouza_CSPractical6.ipynb - Colaboratory
enter name: vrudhi
enter designation: hr
NAME: jaiden
DESIGNATION: ceo
NAME: vrudhi
DESIGNATION: hr
TASK 2 Q3
class Student:
def __init__(self, name, id, marks):
self.name = name
self.id = id
self.marks = marks
def calc(self):
self.tot = self.marks[0]+ self.marks[1]
self.perc = self.tot/2.0
def display(self):
if self.perc >= 40:
print("PASSED")
print("NAME: ", self.name)
print("ID: ", self.id)
print("ENGLISH MARKS: ",self.marks[0])
print("MATHS MARKS: ", self.marks[1])
print("PERCENTAGE: ", self.perc)
else:
print("STUDENT FAILED")
name = input("enter name: ")
id = input("enter id: ")
marks = []
marks.append(int(input("enter english marks: ")))
marks.append(int(input("enter maths marks: ")))
obj = Student(name, id, marks)
obj.calc()
obj.display()
enter id: 4
PASSED
NAME: tanish
ID: 4
ENGLISH MARKS: 95
PERCENTAGE: 97.5
https://colab.research.google.com/drive/1r15kWbohFp_MiI7Hi8k5fvco6_3Ac6Cn#scrollTo=NdUunLs-vaYb&printMode=true 3/5
9/10/22, 5:34 PM E017_JaidenDsouza_CSPractical6.ipynb - Colaboratory
TASK 2 Q4
seat = {"gold": [45,100], "recliner": [20,200], "silver": [40,50]}
class movie:
def __init__(self):
self.name = input("enter name of the movie: ")
self.theatre = ["PVR", "INOX", "CARNIVAL"]
def calc(self):
amt = 0
choice = input("enter name of theatre: ").upper()
if(choice not in self.theatre):
print(" movie is not available here ")
else:
num = int(input("enter number of tickets: "))
ty = input("enter type of seat: ").lower()
if(num > seat[ty][0]):
print("there are not enough seats")
else:
meal = input("do you want a meal (yes/no): ").upper()
amt = num * seat[ty][1]
amt += amt*0.18
if(meal == "YES"):
amt += 50
seat[ty][0] -= num
print("")
print("BILL DETAILS: ")
print("MOVIE: ", self.name)
print("SEAT TYPE: ", ty)
print("QUANTITY: ", num)
print("MEALS: ", meal)
print("TOTAL: ", amt)
for i in range(0,2):
obj = movie()
obj.calc()
BILL DETAILS:
MOVIE: LOTR
QUANTITY: 5
MEALS: YES
TOTAL: 1230.0
https://colab.research.google.com/drive/1r15kWbohFp_MiI7Hi8k5fvco6_3Ac6Cn#scrollTo=NdUunLs-vaYb&printMode=true 4/5
9/10/22, 5:34 PM E017_JaidenDsouza_CSPractical6.ipynb - Colaboratory
do you want a meal (yes/no): no
BILL DETAILS:
MOVIE: GOT
QUANTITY: 6
MEALS: NO
TOTAL: 708.0
check 58s
completed at 5:34 PM
Could not connect to the reCAPTCHA service. Please check your internet connection and reload to get a
reCAPTCHA challenge.
https://colab.research.google.com/drive/1r15kWbohFp_MiI7Hi8k5fvco6_3Ac6Cn#scrollTo=NdUunLs-vaYb&printMode=true 5/5