class Amenity():
def __init__(self, itemCode, description, price):
self._itemCode = itemCode
self._description = description
self._price = price
def __str__(self):
return "{}, {}, ${:.2f}".format(self._itemCode, self._description, self._price)
class Room():
def __init__(self):
self._amenities = []
def addAmenity(self, newItem):
if newItem in self._amenities:
return "Duplicate found"
else:
self._amenities.append(newItem)
def __str__(self):
amenityListing = "\n".join(str(amenity) for amenity in self._amenities)
return "{} ".format(amenityListing)
def main():
room2 = Room()
room2Amenity1 = Amenity("GYM-PEP","Per entry pass to gym (Level 4-01)",1.00)
room2Amenity2 = Amenity("FRIDGE","Mini Fridge (50L)",4.59)
room2Amenity3 = Amenity("WI-FI","One-day Wi-Fi access",1.00)
room2Amenity4 = Amenity("GYM-PEP","Per entry pass to gym (Level 4-01)",1.00)
room2.addAmenity(room2Amenity1)
room2.addAmenity(room2Amenity2)
room2.addAmenity(room2Amenity3)
print(room2)
print()
room2.addAmenity(room2Amenity4)
print(room2)
Output
GYM-PEP, Per entry pass to gym (Level 4-01), $1.00
FRIDGE, Mini Fridge (50L), $4.59
WI-FI, One-day Wi-Fi access, $1.00
GYM-PEP, Per entry pass to gym (Level 4-01), $1.00
FRIDGE, Mini Fridge (50L), $4.59
WI-FI, One-day Wi-Fi access, $1.00
GYM-PEP, Per entry pass to gym (Level 4-01), $1.00
Expected Output
GYM-PEP, Per entry pass to gym (Level 4-01), $1.00
FRIDGE, Mini Fridge (50L), $4.59
WI-FI, One-day Wi-Fi access, $1.00
GYM-PEP, Per entry pass to gym (Level 4-01), $1.00
FRIDGE, Mini Fridge (50L), $4.59
WI-FI, One-day Wi-Fi access, $1.00
Duplicate found