[Tutor] Is this overkill?
Bradly McConnell
bradly.mcconnell at gmail.com
Sat Jan 21 07:45:07 CET 2006
Greetings all:
I'm new to Python, and have come across and exercise that basically
counts to 100. The idea is to accept user input for an initial
number, and then let the user add additional numbers. I wanted to
give feedback if a number selected would bring the total above 100, so
the user would select a lower number. It looks like I have it
working, but it doesn't seem very efficient. I would like any hints,
help, or comments that you can provide. Below is what I have so far.
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: ")
if lower_number + number > 100:
lower_number = input("Lower!")
else:
number = lower_number + number
elif additional_number + number < 100:
number = additional_number + number
else:
continue
print "Done", number
Brad
More information about the Tutor
mailing list