Python while loop
John Gordon
gordon at panix.com
Wed Nov 30 11:23:57 EST 2016
In <0c642381-4dd2-48c5-bb22-b38f2d5b2b4a at googlegroups.com> paul.garcia2345 at gmail.com writes:
> 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)
> 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?
"count" is an english word meaning "how many things do I have?", but python
doesn't know that. In python, "count" is just a name; you could have
called it "hamburger" and python would treat it just the same.
--
John Gordon A is for Amy, who fell down the stairs
gordon at panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
More information about the Python-list
mailing list