Joshua Richardson
Joshua Richardson

Reputation: 1

Python returning multiple values from a function to another

I am trying to get 2 values from my getValues function and return it as a parameter to my askQuestion function

I get an error:

TypeError: askQuestion() missing 1 required positional argument: 'curA'

#getting a question and index for the answer
def getValues():
    curQ = r.choice(qs)
    index = qs.index(curQ)
    curA = ans[index]
    #returning question and answer to next function
    return curQ, curA
    
#prompting the user with question for answer
def askQuestion(curQ, curA):
    userA = input(question + ": ")
    userA.upper()
    userA.replace(" ", "")
    #using variable because it wont let me carry it over
    answer.append('')
    #returning answer and user's answer
    return curA, userA

askQuestion(getValues())

Upvotes: 0

Views: 81

Answers (1)

Barmar
Barmar

Reputation: 782407

Use the spread operator to separate the return tuple into separate arguments.

askQuestion(*getValues())

Upvotes: 2

Related Questions