How do I use a for loop to find the sum of a range in Python?
A 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:
- sum = 0
- for i in range(11):
- sum = sum + i
- print("sum of a range is", sum)
when we adding the numbers, the output will be 55.
Comments
Post a Comment