I'm working on a program that prompts a user for a number within a range of integers they've entered. If the number they enter is out of range, they're prompted to give another, and if they enter a letter instead they're prompted to change their answer as well. Here is what I've got:
def code_one(d, f):
s = input('Enter a number between' + str(d) + 'and' + str(f) + ': ')
s = int(s)
if int(d) <= s <= int(f):
return s
else:
while s < int(d) or s > int(f):
s = input(str(s) + 'is out of range. Please try again. ')
s = int(s)
if s < int(d) or s > int(f):
continue
else:
return s
while s.isdigit == False:
s = input(str(s) + 'is not a number. Please try again.' )
if s.isdigit == False:
continue
else:
return s
It works fine up until the line reading "while s.isdigit == False:" and then, if I input a letter instead of a number, I get the error "invalid literal for int() with base 10: 'x'", (the x being whatever letter I happen to enter). What can I do to fix this?