I’m trying to support repetition where the user inputs a filename, then inputs two integers. So if an exception is thrown, I want the user to be prompted with input again.
My problem is if a valid file is entered but an invalid integer is entered it will ask for the file again instead of just the integer. How can I fix the code so it will ask for the integer again.
Here is what I have:
while True:
try:
f = raw_input("Enter name of file: ")
inFile = open(f)
# more code
except IOError:
print ("The file does not exist. Try Again.")
else:
try:
integer = int(raw_input("Enter an integer: "))
integer2 = int(raw_input("Enter an integer: "))
# more code
except (TypeError, ValueError):
print ("Not an integer. Try Again.")
Try use multiple
whileloops: