mercredi 12 septembre 2018

While Loop complication in guess the number game

So I am making the guess the number game in Python 3

After the whole process, I want my while loop to generate another number so that I can start the game again without running the program again. Please let me know what I'm doing wrong and if you could provide me with some insight on how to use the while loop it'll be much appreciated.

Here's the code :

import random

while True:

number = random.randint(1, 1000)

count = 0

guessed = input("Enter the number you guessed: ")
count += 1

if int(guessed) < number:
    print("You guessed too low")
elif int(guessed) > number:
    print("You guessed too high")
elif int(guessed) == number:
    print(f'You guessed right and it took you {count} guesses to the right number which is {number}')




Aucun commentaire:

Enregistrer un commentaire