0

Hi, I have a problem with a sequence. The sequence is a number range from 1 to 100. I need to show each number and also the running total of each number. for example First number in sequence is 1, running total 1. Next number in sequence is 2, running total is 1+2 = 3. and so on. I need to use the while function.

n = 1
while n < 101 :
print n
n = n+1
This gives me the sequence. Just dont know how to do the running total


Thanks in advance
Apsu

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by apsu
0

Please use code tags around your code.
Something like this will do the summation:

sum = 0
n = 1
while n < 101 :
    sum += n
    print n, sum
    n = n+1

Note that sum += n is the same as sum = sum + n

Proper code tags are
[code=python]
your Python code here

[/code]

0

Thankyou so much sneekula, really appreciate it. I am new here and forgot to use the code rules. am sorry for that.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.