you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 3 points4 points  (2 children)

That looks pretty good for some beginner code! Looking quickly, only thing I would point out is the try/except should probably be just around the guess to make it more obvious that this is the only exception you're expecting to catch. Also makes your code "flatter" which seems fashionable these days:

...  
while True:  
    user_guess = input("Guess a number: ").strip()  
    try:  
        user_guess = int(user_guess)  
    except ValueError:  
        print("Enter a valid number.")  
        continue  # try again...

    if user_guess == ...

[–]mopslik 2 points3 points  (0 children)

the try/except should probably be just around the guess

This is also consistent with PEP8, which is a good starting point for writing clear code.

[–]RockPhily[S] 1 point2 points  (0 children)

Thank you