There is an issue with the program when the user correctly guesses the number. The program should end when the break statement executes in the while loop found in main(), but instead it times out.
import random
def main():
level = get_level()
number = generate_random_number(level)
while True:
guess = get_guess()
if check_guess(number, guess) == False:
continue
else:
break
def get_level():
while True:
level = input("Level: ")
try:
int(level)
except ValueError:
continue
if int(level) <= 0:
continue
else:
return int(level)
def generate_random_number(level):
number = random.randint(1, level)
return number
def get_guess():
while True:
guess = input("Guess: ")
try:
int(guess)
except ValueError:
continue
if int(guess) <= 0:
continue
else:
return int(guess)
def check_guess(number, guess):
if guess > number:
print("Too large!")
return False
if guess < number:
print("Too small!")
return False
if guess == number:
print("Just right!")
return True
main()
Nothing really sticks out. It could also be something about how the automated checker provides input (maybe it expects to not press enter or something and it’s stuck at input()… hard to say)
I personally would install ruff and run “ruff check yourfile.py” and then later “ruff check --select=ALL yourfile.py” and read about everything it complains about.
Google the error codes and find the description and discussion of each and why it is complaining, sometimes they’re not a big deal, sometimes they are aha moments. Ruff has a page discussing each warning and error
https://docs.astral.sh/ruff/rules/
Actually I think it may be your get_entry() code. The try traps all non-numbers and restarts the loop for new entry. So like typing “exit” or an empty string or anything that’s not convertible to a number is being trapped by the raise and sent back for reentry. And anything that is a number can’t hit the break. Just my guess.
I second this! Add a print(“invalid number, try again”) or something to verify and avoid silent failures.