0% found this document useful (0 votes)
47 views

While Sum - Py

This Python code uses a while loop to sum the integers from 1 to 20. It initializes a total and counter variable i to 0 and 1 respectively. The code iterates from i to 20, adding the current i to the running total on each loop. After the loop, it prints the final total.

Uploaded by

Gaurav Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

While Sum - Py

This Python code uses a while loop to sum the integers from 1 to 20. It initializes a total and counter variable i to 0 and 1 respectively. The code iterates from i to 20, adding the current i to the running total on each loop. After the loop, it prints the final total.

Uploaded by

Gaurav Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

10/29/2018 while_sum.

py

1 # sum : 1 to 10(or any number)


2 total = 0
3 i = 1 # i = 2
4 while i <= 20:
5 total += i # total = total + i
6 i += 1
7 print(total)
8 # total = 0 + 1 + 2 + 3 + 4

https://www.dropbox.com/s/w2xdubg6tw8dkvb/while_sum.py?dl=0 1/1

You might also like