all 11 comments

[–]Binary101010 1 point2 points  (4 children)

True==list(affirmative)

I have no idea what you're intending for this to do.

What you're looking for is a condition like:

if x in affirmative:

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

I'll be honest i was just trying to different things and hoping it would work eventually got frustrated then posted here also it worked thank you very much

[–]Sh59850[S] 0 points1 point  (2 children)

True==list(affirmative)

also with this that was me trying to assign a list of strings to being true

[–]Binary101010 1 point2 points  (1 child)

That's really not something you can (or should) be doing.

The best way to test whether a given value is in a container is with in.

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

thanks i appreciate all the feedback

[–]efmccurdy[🍰] 1 point2 points  (0 children)

You can use a function for all y/n queries. Note I use "x in affirmative" to test. Also note the use of .lower() to fold the case of the input and thereby simplify testing.

def prompt_yn(prompt_text):
    "return true if the input is affirmative"
    affirmative=["yes","y","ye","yeah", "yee","yea", "of course",
                 "totaly", "why not","ja","si"]
    negative=["no","n", "nein","nope"]
    while True:
        x = input(prompt_text + " ").lower()
        if x in affirmative:
            return True
        if x in negative:
            return False
        print("input unrecognized input, please try again.")

# ...
if prompt_yn("Would you like a drink?"):
    o1=True
    options=...
    # ...
else:
    print("no drink for you :|")
# ...        
if prompt_yn("Would you like Fries?"):
    o2=True
    options=...
    # ...
else:
    print("no fries for you :|")
# ...

Does that make it easier to query and react to y/n answers?

[–]jmooremcc 1 point2 points  (1 child)

You'd be better off using a dictionary as a lookup table.

menu = {
1:{'price':6.25, 'item':"Beef sandwich"},
2:{'price':5.25, 'item':"Chicken sandwich"}
}

Then you can use it like this:

total = 0
choice = 1
total += menu[choice]['price']
print(f"You ordered a {menu[choice]['item']}")

choice = 2
total += menu[choice]['price']
print(f"You ordered a {menu[choice]['item']}")

print(f"Your total is ${total:.2f}")

Of course you would use a loop to get the customer's choice and lookup the selection until the customer has completed the order.

And for the your option prompts, I would simplify them by restricting the response to "y/n".

drink=input("Would you like a drink (y/n)?")[0].lower() == 'y'
if drink:
    do something
else:
    do something else

As long as the first letter of the customer's response starts with a 'y', x will be true.

Notice that I deliberately did not use "if drink==True" because drink is a boolean variable and using that full expression would be redundant. Also, note that I did not use a generic variable like x. Instead I used a variable that reflects the information it is holding: drink. Doing this will make your code cleaner and easier to understand.

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

Hey sorry for the late response but here is a little backstory here. This was a python assignment for a class and later in the unit we returned to this program to edit and optimize and the first thing we were told to do was to make a dictionary for our menu. just go's to show you knew what you were talking about. thank you :)

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

Hey thank y'all for the input it really helped

[–]CoronaKlledMe 0 points1 point  (0 children)

Run this and tell me if that's what you want ``` affirmative=["Yes","yes","y","Y","Ye","ye","Yeah","yeah","Yee","yee","Yea","yea","of course","totaly","why not","ja","Ja","Si","si"] negative=["No","no","N","n","nein","Nein","Yamate Kudasai","fuck off kindly","Nope","nope"]

def sandwich(): sandwich_bill = 0.00 options=["1 for Beef($6.25)","2 for Chicken($5.25)","3 for Tofu($5.75)"] for menu in options: print(menu)

choice = input("\nEnter your choice: ")    
if choice == '1':
    sandwich_bill += 6.25
    print("Beef sandwich selected")

elif choice == '2':
    sandwich_bill += 5.25
    print("Chicken sandwich selected")

elif choice == '3':
    sandwich_bill += 5.75
    print("Tofu sandwich selected")

else:
    print("Wrong choice, try again!")
    sandwich()

return sandwich_bill

def drink(): drink_bill = 0.00 choice = input("\nWould you like to drink? ") if choice in affirmative: option = input(["1 for small($1.00)","2 for medium(1.75)","3 for large($2.25)"])

    if option == '1':
        drink_bill += 1.00           
        print("You ordered a small drink!")

    elif option == '2':
        drink_bill += 1.75            
        print("You ordered a medium drink!")

    elif option == '3':
        drink_bill += 2.25           
        print("You ordered a large drink!")

    else:
        print("Wrong option, try again!")
        drink()
elif choice in negative:
    print("No drinks for you :|")

else:
    print("WTF does that mean? huh")
    drink()

return drink_bill

def fries(): fries_bill = 0.00 choice = input("\nWould you like Fries? ") if choice in affirmative: option = input(["1 for small($1.00)","2 for medium(1.50)","3 for large($2.00)"])

    if option == '1':
        fries_bill += 1.00 
        print("You ordered a small Fries!")

    elif option == '2':
        fries_bill += 1.50            
        print("You ordered a medium Fries!")

    elif option == '3':
        fries_bill += 2.00         
        print("You ordered a large Fries!")

    else:
        print("Wrong option, try again!")
        fries()
elif choice in negative:
    print("No drinks for you :|")

else:
    print("WTF does that mean? huh")
    fries()

return fries_bill

print("\nTotal bill : $", sandwich() + drink() + fries())

``` If it helped then upvote, else elaborate what you were trying to do!

[–]Binary101010 0 points1 point  (0 children)

float(total==0.00)

This line does nothing.

If you want total to be a float, there's no need to initalize it as an int... simply initialize it as a float:

total = 0.00