+ 11

Change variable in first while loop in two while loops, without globals.

a=1 #the variable I want changed while a == 1: b=2 while b == 2: a=3 #this is local, but I want it to affect the a variable on the first line without using global. print(a)

3rd May 2017, 11:12 PM
Ahri Fox
Ahri Fox - avatar
4 Réponses
+ 17
The code above should print 3 for variable a by adding a single line to break nested loop. Am I missing something or is it simply printing the local variable instead?
3rd May 2017, 11:18 PM
Hatsy Rei
Hatsy Rei - avatar
+ 22
interesting q. bc this variant would work in c# p.s. I`m not python coder. yet.
3rd May 2017, 11:16 PM
Illusive Man
Illusive Man - avatar
+ 15
Glad I helped. c:
3rd May 2017, 11:22 PM
Hatsy Rei
Hatsy Rei - avatar
+ 11
@Hatsey Rei nope, I think that's the answer I'm looking for
3rd May 2017, 11:21 PM
Ahri Fox
Ahri Fox - avatar