mercredi 1 juillet 2020

Python - Why is my simple else statement not working correctly in my while loop? (Noob question)

I'm a noob and probably dumb, but help is appreciated greatly. I want to know why the code finishes when it executes the "else" statement, I want it to continue the "while" loop.

import random
happy == "no"
while happy == "no":
    stat = random.randint(1,50)
    print (stat)
    happy = input("Are you happy with this?" )
    if happy == "yes":
        print("Okay moving on. ")
        break
else:
    print("Please enter a valid answer. ")

Aucun commentaire:

Enregistrer un commentaire