[Tutor] n.isalnum() is failing

Alan Gauld alan.gauld at btinternet.com
Wed Jul 4 02:07:25 CEST 2007


"Terry" <terry.kemmerer at gmail.com> wrote 

> Wow! Those changes radically change the program! 
> 
> Is there a way to get the try-exception to cause the 
> end user questions to be repeated until acceptable 
> answers are given? 

Put the whole blocxk inside a while loop:

start = end = None
while start == None:
   try:
     start = int(raw_input("Enter yyyy for beginning year : "))
     end = int(raw_input("Enter yyyy for ending year : "))
   except ValueError: 
      print "Must be a integer number as YEAR."
      start = end = None

> I also noticed that I had to make the statement "start = end = 0" 

You shouldn't need to but its better to do so.
For one thing if you don't (before we introduce the 
loop which needs start to be there) and the 
error occurs then start and end won't exist

HTH,

Alan G.



More information about the Tutor mailing list