error handling in user input: is this natural or just laborious

sam python.sam at googlemail.com
Fri Oct 6 20:19:01 EDT 2006


this does what i want, though i don't like the inner while loop having
to be there


def get_pct():
	while True:
		pct_list=[['cash', 0], ['bond', 0], ['blue', 0], ['tech', 0], ['dev',
0]]
		total=0
		for i in range(len(pct_list)):
			while True:
				pct_list[i][1]=raw_input('Please enter the percentage value for %s:
' %pct_list[i][0])
				if pct_list[i][1].isdigit() == False:
					print "You've messed up, do it again..."
				else:
					total+=int(pct_list[i][1])
					break
		if total == 100:
			return pct_list
			break
		else:
			print "You've messed up, do it again..."


gosh, a lot of work to get some input. i must be missing something,
though this is a lot better than what i had before...




More information about the Python-list mailing list