C
C
Coder 14482020-06-13 09:09:14
Python
Coder 1448, 2020-06-13 09:09:14

Why doesn't the function read the entered value with input()?

Why does it throw an error here: NameError: name 'y' is not defined ?

def f():
  y = input()

f()

print(y)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-06-13
@wows15

y is defined locally in the function and does not exist outside of it. If you want, you can write in a function
return input()
AND then do
y = f()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question