Resolved: Understanding rolling sum & variable of increment
For below function, I can't understand why we created a variable Total to equal zero & why we further increment it by 1. Our aim is to count existing numbers less than 20 so what is the necessity of growing the total by 1.
def count(numbers):
total=0
for x in numbers:
if x<20:
total+=1
return total
1 answers ( 1 marked as helpful)
Hi Asmaa!
Thanks for reaching out.
The variable total
is initialized to 0 and is used to keep track of the count of numbers less than 20. Each time a number in the list numbers
is found to be less than 20, the total
variable is incremented by 1 to reflect this count.
Hope this helps.
Best,
Tsvetelin