Re: [Tutor] validating user input

2011-04-24 Thread ALAN GAULD
> "Rance Hall" wrote > > >But you have just finished enumerating them and I holds > >the index of the last item, or in your case the count of > >the last item. But even without that you can always > >use len() to find out how many menuchoices there are... > > I knew about len, but somehow didnt t

Re: [Tutor] validating user input

2011-04-23 Thread Rance Hall
On Sat, Apr 23, 2011 at 6:38 PM, Alan Gauld wrote: > > "Rance Hall" wrote > >> Ok, so I have this code that is working, but does little to validate >> user input and I don't quite yet understand that process yet. >> >> so given the following function: >> >> def buildmenu(menuchoices): >>   for i,

Re: [Tutor] validating user input

2011-04-23 Thread Alan Gauld
"Rance Hall" wrote Ok, so I have this code that is working, but does little to validate user input and I don't quite yet understand that process yet. so given the following function: def buildmenu(menuchoices): for i, option in enumerate(menuchoices, 1): Interesting, I didn't know enume

[Tutor] validating user input

2011-04-23 Thread Rance Hall
Ok, so I have this code that is working, but does little to validate user input and I don't quite yet understand that process yet. so given the following function: def buildmenu(menuchoices): for i, option in enumerate(menuchoices, 1): print('%s. %s' % (i, option)) menuchoice = in

Re: [Tutor] validating user input for cli app

2010-10-07 Thread Alan Gauld
"Rance Hall" wrote I'd like to be able to just ask the question again, and re-validate the new input or offer a "press q to quit" option Thats what loops are for... The old GOTO syntax that everybody hates was ideal for this type of thing, if validation fails, just goto the question again

Re: [Tutor] validating user input for cli app

2010-10-07 Thread Steven D'Aprano
On Thu, 7 Oct 2010 12:09:31 pm Rance Hall wrote: > I know how to write the if statements to decide if the data entered > is valid or not, but I need a way to deal with what happens when it > is NOT valid. > > I'd like to be able to just ask the question again, and re-validate > the new input or of

[Tutor] validating user input for cli app

2010-10-07 Thread Rance Hall
I have the following scenario, during a cli app a function is called whose purpose is to get enough info from user to create a database record. Clearly the input values need to be validated. How do I handle the situation where validation fails, but the answer to the question is required. so far