# see if input is an integer digits = "0123456789" inp = raw_input("Type your input: ") # # 1. ignore leading, training blankd # inp = inp.strip() # # 2. be sure something is there # length = len(inp) if length == 0: isnum = "no" else: # # 3 look for a leading "+" or "-" and skip over it # position = 0 if inp[position] == "+" or inp[position] == '-': position = 1 # # 4. now just check for digits; if there's a non-digit, say no # isnum = "yes" while position < length: if not (inp[position] in digits): isnum = "no" position = position + 1 # # 5. announce the result # if isnum == "yes": print "The integer you typed is", int(inp) else: print "You didn't type an integer"