Your main issue was that you weren’t prompting them in the loop.
import random
x = random.randrange(1,1000)
counter = 0
while True:
guess = int(input("I have a number between 1 and 1000. Can you guess my number?\nPlease type your first guess."))
if guess == x:
print ("Excellent! You guessed the number in", counter,"tries.")
break
else:
if guess > x:
print("high")
else:
print("low")
counter += 1
To prompt the user if they wish to play again, you’d do the following:
import random
x = random.randrange(1,1000)
counter = 0
while True:
guess = int(input("I have a number between 1 and 1000. Can you guess my number?\nPlease type your first guess."))
if guess == x:
print ("Excellent! You guessed the number in", counter,"tries.")
play_again = input("Type Y if you'd like to play again, or N if not")
if play_again == 'N':
break
else:
if guess > x:
print("high")
else:
print("low")
counter += 1
1
solved Python: Looping issue or indentation