[Tutor] Is this overkill?
Alan Gauld
alan.gauld at freenet.co.uk
Sat Jan 21 10:32:47 CET 2006
number = input("Please enter a number: ")
while number != 100:
additional_number = input("Please enter an additional number: ")
if additional_number + number > 100:
lower_number = input("please enter a lower number: ")
you can just 'continue' here since the while loop asks for a new
number anyhow. It xchanges the behaviour salightly in that it never
allows a number that sums to more than 100 whereas you allow
only two attempts.
if lower_number + number > 100:
lower_number = input("Lower!")
else:
number = lower_number + number
elif additional_number + number < 100:
so the lines above become unnecessary.
number = additional_number + number
else:
continue
you don't need the last else/continue, thats pythons standard behaviour.
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list