Untitled
unknown
plain_text
2 years ago
4.4 kB
16
Indexable
import csv import datetime menu = """* Lütfen Bir Pizza Tabanı Seçiniz: 1: Klasik 2: Margarita 3: TürkPizza 4: Sade Pizza * ve seçeceğiniz sos: 11: Zeytin 12: Mantarlar 13: Keçi Peyniri * Teşekkür ederiz!""" with open('Menu.txt', 'w',encoding="utf-8") as f: f.write(menu) class Pizza: def __init__(self, description): self.description = description def get_description(self): return self.description def get_cost(self): pass class ClassicPizza(Pizza): def __init__(self): super().__init__("Klasik Pizza") def get_cost(self): return 20.0 class MargheritaPizza(Pizza): def __init__(self): super().__init__("Margarita Pizza") def get_cost(self): return 25.0 class TurkishPizza(Pizza): def __init__(self): super().__init__("Türk Pizza") def get_cost(self): return 30.0 class Decorator(Pizza): def __init__(self, component): self.component = component def get_cost(self): return self.component.get_cost() + Pizza.get_cost(self) def get_description(self): return self.component.get_description() + ' ' + Pizza.get_description(self) class Olive(Decorator): def __init__(self, pizza): super().__init__(pizza) self.description = "Zeytin" self.cost = 3.0 def get_description(self): return self.component.get_description() + ' ' + self.description def get_cost(self): return self.component.get_cost() + self.cost class Mushroom(Decorator): def __init__(self, pizza): super().__init__(pizza) self.description = "Mantarlar" self.cost = 4.0 def get_description(self): return self.component.get_description() + ' ' + self.description def get_cost(self): return self.component.get_cost() + self.cost class GoatCheese(Decorator): def __init__(self, pizza): super().__init__(pizza) self.description = "Keçi Peyniri" self.cost = 5.0 def get_description(self): return self.component.get_description() + ' ' + self.description def get_cost(self): return self.component.get_cost() + self.cost def main(): # Menüyü ekrana yazdırma print("-------MENU-------") with open("Menu.txt", "r",encoding="utf-8") as f: menu = f.read() print(menu) while True: # Pizza türü seçme pizza_type = input("Lütfen bir pizza türü seçin (1-3): ") if pizza_type not in ["1", "2", "3"]: print("Lütfen geçerli bir pizza türü seçin.") continue pizza_type = int(pizza_type) if pizza_type == 1: pizza = ClassicPizza() elif pizza_type == 2: pizza = MargheritaPizza() elif pizza_type == 3: pizza = TurkishPizza() else: break # Pizza malzemesi seçme toppings = [] while True: topping_type = input("\nLütfen pizzaya eklemek istediğiniz malzemeleri seçin (0 tamam): ") if topping_type == "0": break if topping_type == "11": toppings.append(Olive(pizza)) elif topping_type == "12": toppings.append(Mushroom(pizza)) elif topping_type == "13": toppings.append(GoatCheese(pizza)) else: print("Lütfen geçerli bir malzeme seçin.") # Fatura hesaplama ve yazdırma total_cost = pizza.get_cost() for topping in toppings: total_cost += topping.get_cost() print("Toplam tutar: ", total_cost, "TL") # Sipariş kaydetme with open('orders.csv', mode='a', newline='') as order_file: order_writer = csv.writer(order_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) now = datetime.datetime.now() order_writer.writerow([now.strftime("%Y-%m-%d %H:%M:%S"), pizza.get_description(), [topping.get_description() for topping in toppings], total_cost]) if __name__ == "__main__": main()
Editor is loading...