Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Just a bit confused
#1
So I am trying to figure out how to display a menu in the current code where it prompts the user to display a menu like this

please choose a flavor
1.Savanah
2.Tagalong
3.Thinmints

where I am confused is I'm trying to capture the numerical input from the user, so if they enter 1 that means they selected the first flavor, then they tell me how many and what not. Here is what I have so far. I'm new to python this is my fifth week.

#Input

print("Hello welcome to my store")
print()
order_total = 0
item_cnt = 0
1 = int(input("Savanah")
2 = int(input("ThinMints")
3 = int(input("Tagalongs")
cont = input("Would you like to start? (y/n)>")

print('-' * 30)
print('order for your name')
print('Item Name   Price   Qty   total')

while cont.lower() == "y":
    input("Please choose a flavor {} {} {}".format(1, 2, 3))
    item_name = input("Enter cookie name>")
    item_price = int(input("enter item price>"))
    item_qty = int(input("enter item quanity>"))
   

    #Process
    item_total = (item_qty * item_price)
    order_total += order_total + item_total
    item_cnt += 1


    #Output

    print("{}.{} price:${} qty:{} total:${}.".format(item_cnt, item_name,item_price, item_qty, item_total))
    print("There are {} items in the order for a total of ${}".format(item_qty, item_total))
    cont = input("would you like to start another order? (y/n))")
    
    print("You ordered {} items for a total price of ${}".format(item_cnt, order_total))
    print("Thank you for your order")
    print()
    print("Thank you for using this program")
Reply
#2
this:
1 = int(input("Savanah")
2 = int(input("ThinMints")
3 = int(input("Tagalongs")
is taboo.
You are essentially trying to override the numbers 1, 2 and 3
do this like:
choice = 0
while choice not in [1, 2, 3]:
    print('Please choose one of:')
    print("    1. Savanah")
    print("    2. ThinMints")
    print("    3. Tagalongs")
    choice = int(input())
print('You have chosen option: {}',format(choice))
Reply
#3
Thank you Larz! That was very helpful!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  i'm confused with this if-else assignment gabejohnsonny21 4 1,827 Mar-14-2020, 03:56 PM
Last Post: gabejohnsonny21

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020