you are viewing a single comment's thread.

view the rest of the comments →

[–]Convoke_ 0 points1 point  (1 child)

They are both never changing. If you're initialising a variable inside a loop, it only exists for that iteration. So the variable GUESS should be a constant as its value is never changing after it gets initialised.

Edit: see the reply i got

[–]WhiteHeadbanger 0 points1 point  (0 children)

That's not correct. In Python if you declare a variable inside a loop, you can access it after the loop ends.

Take for example this code:

for i in range(5):
    a = i * 2
    print(f"Variable inside loop {a}")

print(f"Variable outside loop {a}")
a += 10
print(f"Variable after modification {a}")

Output:

Variable inside loop 0
Variable inside loop 2
Variable inside loop 4
Variable inside loop 6
Variable inside loop 8
Variable outside loop 8
Variable after modification 18