mardi 6 octobre 2020

Problems with if else statements using python

Learning how to create if else statements and struggling. I don't understand the final output. If the answer is "N" then the while raining part should no longer be valid and it should move to the else statement. That does happen, but why is it printing out "stay inside and wait"? That's not part of the else statement?

Raining = input("Is it raining outside? Press Y or N")

if Raining == "N":
    print("Go outside")
    exit
if Raining == "Y":
    print()
    print("Stay inside and wait")
    print()
    while Raining == "Y":
        Raining = input("Is it still raining outside?")
        print()
        print("Stay inside and wait")
    else:
        print("Go outside")
        exit ()

Output:

Is it raining outside? Press Y or NY

Stay inside and wait

Is it still raining outside?Y

Stay inside and wait Is it still raining outside?N

Stay inside and wait Go outside

Aucun commentaire:

Enregistrer un commentaire