下面是修改后的代码:
class Meat:
nums = 0
class Egg(Meat):
name = "鸡蛋"
price = 1
class Beef(Meat):
name = "牛肉"
price = 25
class Mutton(Meat):
name = "羊肉"
price = 30
class Vegetable:
nums = 0
class Onion(Vegetable):
name = "洋葱"
price = 2
class Tomato(Vegetable):
name = "番茄"
price = 2
class Potato(Vegetable):
name = "土豆"
price = 3
class Radish(Vegetable):
name = "萝卜"
price = 3
class Chicken(Vegetable):
name = "鸡肉"
price = 6
class Bread(Vegetable):
name = "面包"
price = 4
class Menu:
def order(self):
self.x = []
print("客官想要吃点什么?")
dishes = input("1.洋葱炒牛肉;2.洋葱炒羊肉;3.煎蛋;4.番茄炒蛋;5.土豆萝卜炖羊肉;6.汉堡:")
dishes = dishes.split()
while dishes:
dish = dishes.pop(0)
if dish == '1':
onion = Onion()
onion.num = 1
beef = Beef()
beef.num = 1
self.x.extend([beef, onion])
elif dish == '2':
onion = Onion()
onion.num = 1
mutton = Mutton()
mutton.num = 1
self.x.extend([mutton, onion])
elif dish == '3':
egg = Egg()
egg.num = 2
self.x.append(egg)
elif dish == '4':
tomato = Tomato()
tomato.num = 2
egg = Egg()
egg.num = 3
self.x.extend([tomato, egg])
elif dish == '5':
potato = Potato()
potato.num = 2
radish = Radish()
radish.num = 1
mutton = Mutton()
mutton.num = 2
self.x.extend([potato, radish, mutton])
elif dish == '6':
chicken = Chicken()
chicken.num = 1
bread = Bread()
bread.num = 1
self.x.extend([bread, chicken])
def pay(self):
total = 0
for each in self.x:
print(each.name, each.price, "*", each.num)
total += each.price * each.num
print(f"感谢惠顾,您一共消费了 {total} 元,欢迎下次光临~")
在这个修改后的代码中,主要修改了以下几点:
· 将 Mutoon 修改为正确的拼写 Mutton。
· 将 chicken 修改为 Chicken,将 bread 修改为 Bread。
· 添加了适当的缩进以形成更清晰的代码结构。
希望这个修改后的代码能满足你的需求!如果还有其他问题,请随时提问。
如果问题已经解决,请设置最佳答案 |