How do I use a for loop to find the sum of a range in Python?

 for loop is used for iterating over a sequence.

With a for loop, we can execute a series of expressions, once for each element of a list, tuple, set, etc.

Let's see an example:

  1. sum = 0 
  2. for i in range(11): 
  3. sum = sum + i 
  4. print("sum of a range is", sum) 

when we adding the numbers, the output will be 55.


Comments

Popular posts from this blog

proassignment help backlink data index 41

programming shark backink data index 31

Programming shark backlink data index 67