I have gone through your code and there were some issues in the code. I have fixed the issue, kindly check in the below program:
import random
number = random.randint(1, 100)
player_name = input("Hello, What's your name?")
number_of_guesses = 0
print('okay! '+ player_name+ ' I am guessing a number between 1 and 100:')
max_guesses = random.randint(1, 6)
print(f"You have {max_guesses} tries. ")
won = False
while number_of_guesses < max_guesses:
guess = int(input())
number_of_guesses += 1
if guess < number:
print("Your guess is too low")
if guess > number:
print("Your guess is too high")
if guess == number:
won = True
break
if won:
print("You guessed the number in " + str(number_of_guesses) + " tries!")
else:
print("You did not guess the number, the number was " + str(number))
Still, this looks like some starting-out project, so it is very necessary to know what every code line is executing.
Want to be a Python expert? Join this Python Training course by Intellipaat to learn more.