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

Asked By: gupta

||

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)
Answered By: bashrc
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.