I am writing a Python program to create projects on my computer for different programming languages. This starts off with the language for this specific project being chosen, and I was trying to do it in a way that handled errors reasonably well.
So far I have this code.
def prompt_user():
print "Enter the number of the project you would like to create.\n"
aOptions = ["1. Java", "2. C/C++", "3. Python", "4. Web"]
for sOption in aOptions:
print sOption
try:
iOptionChosen = int(raw_input("> "))
if not(1 <= iOptionChosen <= 4):
raise ValueError
else:
return iOptionChosen
except ValueError:
print "\nInvalid value entered. Try again."
prompt_user()
print prompt_user()
It works well for what I need it to do, except for the fact that after an exception is raised and the user is reprompted, it never reassigns the new variable to iOptionChosen. Why is this and is there a simple fix? It is so frustrating.
Thanks so much for the help!