Checking if raw_input can be converted to int


As I'm going through this code I notice that that pre-made function converts the raw input to int with the following:
guess = int(raw_input('Your guess: '))

How would I add something into the code that first checks if what that the raw_input is an actual number and not like 'potato' and to resend the raw_input request if it detect a non-number string?



Good question. Always a good idea to doubt and validate user inputs. Having code that makes assumptions is a recipe for disaster.

  1. get the raw input
  2. check it for numberness. TRY comes to mind.
  3. once confirmed as a number pass to program