How do i assign a variable to a function?

  function, python, variables

i’m really new to python and im trying to make a function so that when i call it it assigns something to a variable. idk how to explain it better but this is what i got now:

again = '0'
def printa():
    print(again)
def f1():
    again = '1'
def f2():
    again = '2'
x = input()
x = str(x)
if x == '8':
    f1()
elif x == '9':
    f2()
printa()

My objective is that when I write 8 the output is 1 and when I write 9 the output is 2; and right now the output is always 0. I know I could just write if x == 8 print 1 but I need to use functions…

Source: Python Questions

LEAVE A COMMENT