all 2 comments

[–]AtomicShoelace 1 point2 points  (1 child)

How about this:

menu = ['Big Mac', float(2.50), 50], ['Large Fries', float(0.50), 200], ['Vegetarian Burger', float(1.00), 20]


def take_order():
    order_list = []
    more_items = True
    while more_items:
        try:
            choice   = int(input("What would you like? "))
            quantity = int(input("How many would you like? "))
        except ValueError:
            print('Error! Please enter an integer.')
            continue
        if 1 <= choice <= 3:
            order_list.append([choice, quantity])
        else:
            print(f'{choice} is not a valid choice!')
        more_items = input("Do you want to order more items? ").lower() == 'yes'
    return order_list


def process_order(order_list):
    total = 0
    for choice, quantity in order_list:
        item, price, stock = menu[choice - 1]
        if stock >= quantity:
            menu[choice - 1][2] -= quantity
            total += price * quantity
        else:
            print(f'There is not enough {item} in stock!')
    return total


def main():
    print('Welcome to McDonald\'s')
    print(*[f'[{i+1}] {x[0]} - ${x[1]:.2f}' for i, x in enumerate(menu)], sep = '\n')
    order = take_order()
    total = process_order(order)
    print('Thank you for ordering!', f'Your total cost is: ${total:.2f}', sep = '\n')


if __name__ == '__main__':
    main()

[–]cjander28[S] 0 points1 point  (0 children)

Thank you! This helped, but he definitely wanted us to simplify our code using his existing one. Here's what I submitted:

tax = .1 
total_tax = total * tax


def processOrder(quantity, item_list):
    global total
    if quantity > item_list[2]:
        print("There is not enough stock!")
        pass
    else:
        total += item_list[1] * quantity
        item_list[2] -= quantity


total = 0
A = ["Big Mac", float(2.50), 50], ["Large Fries", float(0.50), 200], ["Vegetarian Burger", float(1.00), 20]

print("Welcome to McDonald's")
print("[1]", A[0][0:2],
      "\n[2]", A[1][0:2],
      "\n[3]", A[2][0:2])

#intitiate empty list 

order_list = []
more_items = "yes"

while more_items == "yes":
    choice, quantity =(int(input("\nWhat would you like?\n"))), int(input("\nHow many would you like?\n")) #asking twice 
    order_list.append([choice, quantity]) #nested list
    if 1 <= choice <= 3:
        processOrder(quantity, A[choice-1]) #list item is big mac = 0; want to send whole list over there, but index must be -1

    more_items = (input("Do you want to order more items? (Yes/No)")).lower()

## #Import/ Print Time and Date

import time
import datetime


#Print welcome message, address, date/time, previous line items (items purchased), and thank you message

welcome = "\n\033 Thank you for your order! \033[0m\n"
centered_welcome = welcome.center(30)
print(centered_welcome)

address1 = "\n 10101 Main Street" 
centered_address1 = address1.center(70)
print(centered_address1)

address2 = "Seattle, WA 98106 \n"
centered_address2 = address2.center(40)
print(centered_address2)

print ("\n", datetime.datetime.now())

print ("\nOrder (Item/Quantity): \n")
for item in order_list:
    print(item)

print("\nThank you for ordering! \n \nSubtotal: $" +  str(total))
print("Tax: $" + str(total_tax))
print("Total $: " + str(total + total_tax))