【发布时间】:2021-12-16 16:26:44
【问题描述】:
我正在尝试从我的 getValues 函数中获取 2 个值并将其作为参数返回给我的 askQuestion 函数
我收到一个错误:
TypeError: askQuestion() 缺少 1 个必需的位置参数:'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())
【问题讨论】:
-
getValues 返回一个包含 (curQ, curA) 的列表,即 1 个变量。您可以更改您的 askQuestion() 函数以获取数组输入
-
@JacksonB 这是一个元组,不是列表或数组。