443,814 Members | 1,050 Online
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

# Ok. This IS homework ...

 P: n/a but I've been struggling with this for far too long and I'm about to start beating my head against the wall. My assignment seemed simple: create a program that will cacluate the running total of user inputs until it hits 100. At 100 it should stop. That's not the problem, in fact, that part works. It's the adding that isn't working. How can my program add 2 + 7 and come up with 14? I'm posting my code (so that you may all laugh). If ANYONE has any ideas on what I'm doing wrong, I'd appreciate. --------------------------------------------------- running = True goal = 100 # subtotal = 0 # running_total = subtotal + guess while running: guess = int(raw_input('Enter an integer that I can use to add : ')) subtotal = guess while running: guess = int(raw_input('I\'ll need another number : ')) running_total = guess + subtotal print running_total if running_total == goal: print 'Congratulations! You\'re done.' elif running_total goal: print 'That\'s a good number, but too high. Try again.' print 'Done' -------------------------- I tried adding an additional "while" statement to capture the second number, but it didn't seem to solve my problem. Help! Oct 14 '06 #1
11 Replies

 P: n/a "spawn"

 P: n/a "spawn"

 P: n/a spawn wrote: while running: guess = int(raw_input('Enter an integer that I can use to add : ')) subtotal = guess while running: guess = int(raw_input('I\'ll need another number : ')) running_total = guess + subtotal You keep adding the original input (subtotal) to the most recent guess, and printing "running_total". You never re-assign subtotal or make use of running_total in your deepest loop. Also, you never break out of your deepest loop, why are you using two nested infinite-loops anyway? Regards, Brett Hoerner Oct 14 '06 #4

 P: n/a Also, you never break out of your deepest loop, why are you using two nested infinite-loops anyway? Regards, Brett Hoerner Ummmmmm ..because I'm new to programming? Actually, they do end. If I move my "guess" variable outside the outermost loop, then it becomes infinte. I know, I tried it. You guys are fast! I'll reread my documentation and try a few more thing (I kept telling myself that running_total and subotal don't need to be different variables!) and see what I get. As for that last post (I don't remember your name), ummmmmm ... WOW! This is BEGINNING Python. That looks far too advanced for me. Oct 14 '06 #5

 P: n/a spawn wrote: Actually, they do end. If I move my "guess" variable outside the outermost loop, then it becomes infinte. I know, I tried it. Huh? When does "running" ever evaluate to false (therefore breaking either of the loops)? Oct 15 '06 #7