#Code runs fine outside of function and doesn't inside it

7 messages · Page 1 of 1 (latest)

marsh sand
#
markX = bool
n = 0

while True:
    n = int(input('1. for X \n2. for O...'))
    if n==1 or n==2:
        break

def fff():
    if n == 1:
        markX = True
    elif n == 2:
        markX = False
    return markX
fff()
print(markX)

It works when put outside of function defination

mighty flame
#

I'm not sure exactly what you are trying to do but you never call your function

marsh sand
mighty flame
#

What are you trying to do? There's some weird stuff going on here such as markX = bool

#

Your markX inside your function is different to the one outside. If you want to use the global markX you'd need to do global markX

#
markX = bool
n = 0

while True:
    n = int(input('1. for X \n2. for O...'))
    if n==1 or n==2:
        break

def fff():
    global markX
    if n == 1:
        markX = True
    elif n == 2:
        markX = False
    return markX
fff()
print(markX)