Beginner Programmer Question
Tim Chase
python.list at tim.thechases.com
Mon Jun 26 14:17:05 EDT 2006
> bigone = 100
>
> number = input("Whats the first number?")
> number2 = input ("Whats the second number?")
> nu3 = number+number2
> while nu3 < bigone:
> print ("Not there yet, next number please")
>
> print "Finally there!"
>
> thats what i thought maybe it was...but after the first two numbers it
> just continually scrolls on the screen with finally there
Gaak! it's doing exactly what you told it to do! Bad program! :)
Inside the loop it neither
1) gets further input from the user nor
2) reassigns/sums nu3
Thus, neither of the elements of your condition (nu3 < bigone)
change, so you're stuck in an infinite loop of printing "not
there yet..."
Here's some sample code that works and does about what you
describe. Tweak accordingly. :)
total = 0
target = 3600
values = [
82, 69, 87, 83, 78, 65, 0, 89, 83, 85, 79, 76, 0, 83, 73,
72, 84, 0, 83, 65, 87, 0, 84, 79, 71, 0, 41, 0, 76, 76,
65, 0, 68, 78, 65, 0, 78, 79, 72, 84, 89, 80, 14, 71, 78,
65, 76, 14, 80, 77, 79, 67, 0, 78, 79, 0, 78, 79, 73, 84,
83, 69, 85, 81, 0, 75, 82, 79, 87, 69, 77, 79, 72, 0, 65,
0, 68, 69, 75, 83, 65, 0, 41
]
while total < target:
# still haven't found the value
value = values.pop() # so we get another number
print chr(value+32), #h have a little fun
total += value #accumulate our total
# and do it until we've accumlated more than target
print "Hey...we're over %s" % target
-tkc
More information about the Python-list
mailing list