0% found this document useful (0 votes)
3 views2 pages

Redo Python

Uploaded by

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

Redo Python

Uploaded by

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

13:43

Ex1:

Class Reservation:
def __init__ (self, guest, paid, room):
self.guest = guest
self.paid = paid
self.room = room
def greet(self):
return(f"welcome {self.guest}, here is your room {self.room}")

reservation = Reservation("Emmanued Macron", True, "R408")

Ex2:

Class LongReservation(Reservation):
def __init__(self, guest, paid, room, month):
super().__init__(guest, paid, room)
self.month = month
def greet(self):
return(f"welcome {self.guest}, here is your room {self.room} in
{self.month} months")

long_reservation = LongReservation(guest="Emmanued Macron", paid = True, room =


"R408", month = 5)

Ex3:
def save(self, filename):
try:
with open(filename, 'w') as file:
file.write(f" Name: {self.guest}\n")
file.write(f" Paid: {self.paid}\n")
file.write (f" Room: {self.room}\n")
file.write (f" Month: {self.month}\n")
print(f"Reservation save to {filename}")
except:
print("Error")

long_reservation = LongReservation(guest="Emmanued Macron", paid = True, room =


"R408", month = 5)
long_reservation.save()

Ex4:

Class LongReservation(Reservation):
def __init__(self, guest, paid, room, month):
super().__init__(guest, paid, room)
self.month = month
def greet(self):
return(f"welcome {self.guest}, here is your room {self.room} in
{self.month} months")
def save(self, filename):
try:
with open(filename, 'w') as file:
file.write(f" Name: {self.guest}\n")
file.write(f" Paid: {self.paid}\n")
file.write (f" Room: {self.room}\n")
file.write (f" Month: {self.month}\n")
print(f"Reservation save to {filename}")
except:
print("Error")
def save_compress(self, filename):
self.save(filename)
compressed_file = f"{filename}.zip"
result = subprocess.run(['zip', compressed_file, filename])
print(f"File compressed as {compressed_file}")

You might also like