Is it possible to design a function from input() and assign a variable to that function call?
Question:
Sorry for the title but I’m not sure how else to word it. Anyway I’m just starting to learn Python and ran into this problem. I’m trying to assign a variable to a function call, where the function contains input()
Unfortunately this never assigns anything to the variable a
def question(letter):
input(letter + '? ')
a = question('a')
print(a)
So I guess my real question is, why doesn’t that work? Why doesn’t it assign the user input to the variable a
?
Thanks
Answers:
You need to return
the user input. Right now the user input is captured nowhere.
def question(letter):
return input(letter + '? ')
a = question('a')
print(a)
Sorry for the title but I’m not sure how else to word it. Anyway I’m just starting to learn Python and ran into this problem. I’m trying to assign a variable to a function call, where the function contains input()
Unfortunately this never assigns anything to the variable a
def question(letter):
input(letter + '? ')
a = question('a')
print(a)
So I guess my real question is, why doesn’t that work? Why doesn’t it assign the user input to the variable a
?
Thanks
You need to return
the user input. Right now the user input is captured nowhere.
def question(letter):
return input(letter + '? ')
a = question('a')
print(a)