Variables in a loop, Newby question

bob gailer bgailer at gmail.com
Tue Dec 24 12:26:09 EST 2013


On 12/24/2013 11:07 AM, vanommen.robert at gmail.com wrote:
> Hello, for the first time I'm trying te create a little Python program. (on a raspberri Pi)
>
> I don't understand the handling of variables in a loop with Python.
>
>
> Lets say i want something like this.
>
> x = 1
> while x <> 10
> 	var x = x
> 	x = x + 1
>
> The results must be:
>
> var1 = 1
> var2 = 2
>
> enz. until var9 = 9
>
> How do i program this in python?
The larger question is "why do you want to do that". It can be done but 
it is almost always a bad idea. Tell us what your goal is and we can 
tell you how we'd go about it.

BTW when checking a condition in a while statement it is better practice 
to say while x < 10. In the above case it does not matter but if you 
were incrementing x by 2 your code would be in an infinite loop, mine 
would still stop.



More information about the Python-list mailing list