From e4a34d60948e25601e401f918168b63eda75a16d Mon Sep 17 00:00:00 2001 From: LegendJurai <die4damers@gmx.de> Date: Wed, 26 Feb 2025 12:39:46 +0100 Subject: [PATCH] Update 33_drive_thru.py That would be a shorter version without all the "if"s --- 6-functions/33_drive_thru.py | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/6-functions/33_drive_thru.py b/6-functions/33_drive_thru.py index 04a1aa3..7814c15 100644 --- a/6-functions/33_drive_thru.py +++ b/6-functions/33_drive_thru.py @@ -1,30 +1,19 @@ # Drive-Thru π # CodΓ©dex -def get_item(x): - if x == 1: - return 'π Cheeseburger' - elif x == 2: - return 'π Fries' - elif x == 3: - return 'π₯€ Soda' - elif x == 4: - return 'π¦ Ice Cream' - elif x == 5: - return 'πͺ Cookie' - else: - return "invalid option" +menu = ['Cheeseburger', 'Fries', 'Soda', 'Ice Cream', 'Cookie'] + +def get_item(i): + return(menu[i - 1]) def welcome(): - print('Welcome to Sonnyboy\'s Diner!') - print('Here\'s the menu:') - print('1. π Cheeseburger') - print('2. π Fries') - print('3. π₯€ Soda') - print('4. π¦ Ice Cream') - print('5. πͺ Cookie') + print("Welcome! Here is our menu:") + print(menu) welcome() -option = int(input('What would you like to order? ')) -print(get_item(option)) +order = int(input("What would you like to order? ")) +if order > 5: + print("Invalid order.") +else: + print(get_item(order))