mardi 22 décembre 2020

How do I only print once in a while loop?

I've read through different posts about this topic, but I was never able to implement their fixes into my code, as they have something completely different to do from my code, or are in a whole different programming language.

Here's my code -

    # Pick a number between 1-20
import random
import time
def freeze(length):
    time.sleep(length)

number = random.randint(1,20)


print('Welcome to guess a number. I\'ll be thinking of a number between 1-20, and you need to guess that number!')
guess = input("\nWell, go ahead, guess!\n")


Alive = True
while Alive == True:
    if int(guess) > number:
        print("Guess to high!")
    elif int(guess) < number:
        print("Guess to low!")
    elif int(guess) == number:
        Alive = False
        print(f"Correct! My number was {number}!")
    elif int(guess) == "":
        Alive = False
        print("Invalid Response!")

Aucun commentaire:

Enregistrer un commentaire