Python Work Around For 'Goto' -
at moment have check see if string has specific characters in it.
i trying find work around 'goto' function.
this have @ moment:
chars = set('0123456789$,') if any((c in chars) c in userinputamount): print 'input accepted' else: print 'invalid entry. please try again'
i need python go string input of 'userinputamount' if entry invalid. push in right direction appreciate.
you don't need goto, need loop. try this, loops forever unless user provides valid input:
chars = set('0123456789$,') while true: # loop "forever" userinputamount = raw_input() # input user if any((c in chars) c in userinputamount): print 'input accepted' break # exit loop else: print 'invalid entry. please try again' # input wasn't valid, go 'round loop again
Comments
Post a Comment