第一张是具体要求 第二张是想达到的结果
1111111111111111111111111111111111111111111
class Item:
def __init__(self, name, price):
self.name = name
self.price = price
self.origin = None
def get_name(self):
return self.name
def get_price(self):
return self.price
def get_origin(self):
return self.origin
def set_name(self, name):
self.name = name
def set_price(self, price):
self.price = price
def set_origin(self, origin):
self.origin = origin
def display(self):
print(f"Name: {self.name}")
print(f"Price: £{self.price}")
print(f"Origin: {self.origin}")
bill = []
while True:
add_item = input("Would you like to add an item to the bill? (YES/NO) ")
if add_item.upper() != "YES":
break
name = input("Enter the name of the item: ")
price = float(input("Enter the price of the item: "))
origin = input("Enter the origin of the item: ")
item = Item(name, price)
item.set_origin(origin)
bill.append(item)
total_payment = 0
for item in bill:
item.display()
total_payment += item.get_price()
print(f"Total payment: £{total_payment}")