lundi 7 mai 2018

if statement wont go to else statment if I enter something other than Y

This is my code which has two sets of if statements and a while loop

def bakingOpt():
tempList3= bakeList
numChoice=""
#user choosing if they want other baking options
answer= input("Would you like to find out the perfect baking time and temperature for your dessert? Y/N:")
if answer == "Y" or "y":
    while True:
        numChoice= input("\nPlease re-enter your dessert choice number:")
        if numChoice == "1":
            print(tempList3[0],"\nEnjoy your brownies!",end="")
            break
        elif numChoice == "2":
            print(tempList3[2],"\nEnjoy your cake!",end="")
            break
        elif numChoice == "3":
            print(tempList3[4],"\nEnjoy your cake!",end="")
            break
        elif numChoice == "4":
            print(tempList3[6],"\nEnjoy your freshly baked loaf of bread!",end="")
            break
        elif numChoice == "5":
            print(tempList3[8],"\nEnjoy your cookies!",end="")
            break
        elif numChoice == "6":
            print(tempList3[10],"\nEnjoy your baked donuts!",end="")
            break
        else:
            print("That was an invalid response, please try again.")
else:
    print("Enjoy!")

For whatever reason when I input an "N" for the if statement:

answer= input("Would you like to find out the perfect baking time and temperature for your dessert? Y/N:")
if answer == "Y" or "y":

The program still continues as if I entered a "Y" or "y" and asks the user to "Please re-enter your dessert number choice". I'm unsure as to why the program won't skip to the second else statement and print "Enjoy" when I type in the "N".

Any feed back would be very helpful. Thank you!

Aucun commentaire:

Enregistrer un commentaire