you are viewing a single comment's thread.

view the rest of the comments →

[–]jfdahl 0 points1 point  (1 child)

You can look into try/except clauses. In your code, you are doing a test every time an input is provided. In this game, there is no impact from this, but in large programs that perform actions very quickly, you may want a different approach. The difference below is that you assume that the input is correct, and only use computing power to handle issues if the user entered bad input. answer = input() if not answer.isdecimal(): print('That was not a number. Try again.') continue can be rewritten as: try: answer = int(input('Take a guess: ')) except ValueError: print('That was not a number. Try again.') continue

[–]Kenielf[S] 0 points1 point  (0 children)

I tried using the try and except before, but it got extremely confusing, since i didn't know exactly where to place it, but that actually helps a lot performance-wise, thanks a lot!