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

Recommended Answers

All 2 Replies

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]

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.