I need some help to get on the right path. This is what I'm trying to do:
- Create a menu: This will be a list with dictionaries that contains some groceries with the price.
- Print the menu.
- Create a list with dictionaries that will be a shopping basket.
- Create some options for the user. (1. add item to shopping basket and the quantity of that item, 2.delete an item, 3.show list, 4.get total cost of the shopping basket and 5.exit)
- Print the options
- Desired output is a program that lets the user choose between the options, they can choose to add groceries to their shopping bag and print the total cost.
This is some code I've tried so far:
menu = [{"item": "milk", "price": 2},
{"item": "eggs", "price": 1},
{"item": "salad", "price": 2},
{"item": "chicken", "price": 4}]
option = int(input("""\n
1. Add item to list
2. Delete item from list
3. Show shopping basket
4. Total cost of your shopping basket
6. Exit\n
Enter an option: """))
if option == 1:
# Add item to basket. Not sure how.
elif option == 2:
# Delete item from basket. Not sure how.
elif option == 3:
# Show shopping basket. Not sure how.
elif option == 4:
# Total cost of your shopping basket. Not sure how.
elif option == 5:
# Exit the program
else:
print("Please enter a valid number (1-6)")
choice = input(""""\n
Milk: $2
Eggs: $1
Salad: $3
Chicken: $4
Enter an item from the menu: """).lower()
shopping_basket = []
add_item = True
while add_item == True:
if choice == "milk":
quantity = int(input("Enter quantity: "))
total_sum = quantity * 2
print("The sum so far is", total_sum)
elif choice == "eggs":
quantity = int(input("Enter quantity: "))
total_sum = quantity * 1
print("The sum so far is", total_sum)
elif choice == "salad":
quantity = int(input("Enter quantity: "))
total_sum = quantity * 2
print("The sum so far is", total_sum)
elif choice == "chicken":
quantity = int(input("Enter quantity: "))
total_sum = quantity * 4
print("The sum so far is", total_sum)
else:
print("Invalid input. Please pick an item on the menu.")
Where do I go from here? Appreciate any help.
Aucun commentaire:
Enregistrer un commentaire