Dec-05-2017, 02:09 PM
Hi. i am trying to make the guess the number, but i am getting an error at the end were i have to replay the game. here is my code:
import random n = random.randint(1, 100) tries=0 guess=0 guess = int(input("Please enter a number from 1 to 100: ")) while n != "guess": tries += 1 points=100-tries if guess < n: print ("\nNumber is bigger than the one you typed.") guess = int(input("Please try again, by typing a number from 1 to 100: ")) elif guess > n: print ("\nNumber is smaller than the one you typed") guess = int(input("Please try again, by typing a number from 1 to 100: ")) elif guess < 1 or guess > 100: print("Number out of range. Please enter a number within range of 1 to 100") else: print ("\nYou found it after", tries," and you won ",points," points") [b]while True: word = input('Would you like to play again? (YES/NO): ') if word == 'NO': break[/b] printthe part of the code with bold is the one that i have issues with. I would like the user to be able to continue playing the game by typing yes or end the game by typing no. Also i would like to limit the number of tries to 10. Could someone evaluate the above code and help me please?