Untitled
class CarWashApp: def __init__(self): self.services = { 1: {"name": "Basic Wash", "price": 10}, 2: {"name": "Deluxe Wash", "price": 20}, 3: {"name": "Premium Wash", "price": 30}, 4: {"name": "Ultimate Wash", "price": 40}, } self.extras = { 1: {"name": "Tire Shine", "price": 5}, 2: {"name": "Interior Cleaning", "price": 15}, 3: {"name": "Waxing", "price": 25}, } def display_services(self): print("\n--- Welcome to the Car Wash App ---") print("Here are our available wash packages:") for key, service in self.services.items(): print(f"{key}. {service['name']} - ${service['price']}") print("\nAdditional Services:") for key, extra in self.extras.items(): print(f"{key}. {extra['name']} - ${extra['price']}") def get_user_choice(self, options, prompt): while True: try: choice = int(input(prompt)) if choice in options: return choice else: print("Invalid choice. Please select a valid option.") except ValueError: print("Invalid input. Please enter a number.") def add_extras(self): print("\nWould you like to add any extra services? (type 0 to skip)") chosen_extras = [] while True: extra_choice = self.get_user_choice( list(self.extras.keys()) + [0], "\nEnter the number of an extra service to add (or 0 to finish): ", ) if extra_choice == 0: break chosen_extras.append(self.extras[extra_choice]) print(f"Added: {self.extras[extra_choice]['name']}") return chosen_extras def calculate_total(self, service_choice, extra_services): total = self.services[service_choice]["price"] for extra in extra_services: total += extra["price"] return total def apply_discount(self, total): print("\nDo you have a discount code? (yes/no)") if input().lower() == "yes": code = input("Enter your discount code: ") if code == "SAVE10": total *= 0.9 # 10% discount print("Discount
Leave a Comment