Q:

Global variable undefined in nested loop

I am trying to do a odd/even number generator and printing the percentage of even numbers WITHOUT using if-then-else statement. However my global variable could not be read in my nested loop, any advise? Thanks!
I have tried this in other languages and it work, however it don't seem to work in python.
import random;

numberArr = [];
noRandomNum = 4;
isEven = 0;

for i in range (0, noRandomNum):
    numberArr.append(random.randint(1,10));

for i in range(len(numberArr)):
    x = numberArr[i]%2;
    # print(isEven);
    while x == 0:
        print("test")
        # isEven++; //UNDEFINED ERROR HERE
        break;

print(isEven);

isEven is a global variable, thus it should work.

A:

There is no ++ operator in python. You have to use it like isEven += 1. Also the semi-colons are not mandatory.
This is not an issue of variable scope.

