Python while loop
MRAB
python at mrabarnett.plus.com
Tue Nov 29 19:46:47 EST 2016
On 2016-11-29 23:58, paul.garcia2345 at gmail.com wrote:
> Write a program which prints the sum of numbers from 1 to 101 ( 1 and 101 are included) that are divisible by 5 (Use while loop)
>
> This is the code:
>
> x=0
> count=0
> while x<=100:
> if x%5==0:
> count=count+x
> x=x+1
> print(count)
>
>
> Question: How does python know what count means ? I see that its declared. What i wanna know is how does it know the iteration or each number it finds divisible by 5 is the "Count" ??
>
It doesn't, it's just a name, and, anyway, in the code, 'x' is the count...
If it _did_ know (which is doesn't), wouldn't it be complaining that
'count' isn't the count but the sum? :-)
More information about the Python-list
mailing list