error handling in user input: is this natural or just laborious
python.sam at googlemail.com
Sat Oct 7 01:53:19 CEST 2006
you're right, of course. it occurred to me that, even if it were
manageable for a few items, it would quickly become absurd as the
number of items grew. this:
pct_list=[['cash', 0], ['bond', 0], ['blue', 0], ['tech', 0], ['dev',
for i in range(len(pct_list)):
pct_list[i]=input('Please enter the percentage value for %s: '
if total == 100:
print "You've messed up, do it again..."
is much better, and easily maintainable by adding to the assignment for
pct_list. still leaves me with checking for strings though, in case
someone types 'donut' at the prompt...
More information about the Python-list