umeeo
umeeo

Reputation: 73

'var' is not defined in 'for' loop

This is a code example from book:

width, height = 240, 60
midx, midy = width // 2, height // 2
for xen in range(width):
    for уen in range(height):
        if xen < 5 or xen >= width - 5 or уen < 5 or уen >= height - 5:
            image[xen, yen] = border_color
        elif midx - 20 < xen < midx + 20 and midy - 20 < уen < midy + 20:
            image[xen, yen] = square_color

When I try to run this, I get error: 'yen' is not defined. But it was defined in 'for' loop, and so 'xen' was defined. I know that the book I am reading is kind of old, but I don't understand why am I getting this error and how to avoid this. I know there are loops, but this code seems fully legit to me. What's the trick?

Upvotes: 2

Views: 27

Answers (1)

Mark
Mark

Reputation: 92461

When I copy and paste your code, the y in yen in your for loop is an odd character (maybe a Cyrillic 'U'). It looks like a y but it's not. Try retyping the line:

for уen in range(height):

These look the same, but if you run the snippet, you'll see they aren't:

console.log("уen" == "yen")

Upvotes: 4

Related Questions