verify input from the user an int between first and last first=10 last=20 What types of errors? -- an int outside the range first to last -- ValueError - something that can't be translated into an int Basic strategy (not yet code): while ans is not valid: get an input and assign it to ans get an input and assign it to ans while ans is not valid: get an input and assign it to ans ---Aside: what should the input call print? ans = input("Enter an int between" + first + "and" + last) There are still a couple problems with the above. ans = input("Enter an int between " + str(first) + " and " + str(last)) However: this is a long line. This is nicer: msg = "Enter an int between " + str(first) msg += " and " + str(last) ans = input(msg) now we have the message... back to the program. ans = input(msg) while ans is not valid: ans = input(msg) ans = input(msg) while ans cannot be converted to an int or (int(ans) < first or int(ans) > last) print error message ans = input(msg) def canBeInt(s): '''s is a string. Returns True if s can be converted into an int, and False otherwise.''' ans = input(msg) ans = "jjj" while not canBeInt(ans) or (int(ans) < first or int(ans) > last): if not canBeInt(ans): print("The value must be an int") else: print("The number must be between",first,"and",last) ans = input(msg) --- def canBeInt(s): '''s is a string. Returns True if s can be converted into an int, and False otherwise.''' #eg: 543\n numbers = "0123456789" returnVal = True # s[-1] is the last char of s # s[:-1] is s without the last char # eg 1j2 for c in s[:-1]: if not c in numbers: returnVal = False returnVal = returnVal and (s[-1] in (numbers + "\n")) return returnVal ===However, we don't want to write canBeInt. we want to use int(), and catch the exceptions thrown by Python. See the python programs on the schedule for Day 15: verifyWithException.py.txt verifyWithExceptions1.py.txt