import random
from random import *
stack = []
num = eval(input("How many words are there?"))
for x in range(num):
w = input("What is the word?")
d = input("Definiton of the word?")
card = (w , d)
stack.insert(0, card)
print(card)
print(stack)
answer = input("What is the word that corresponds with ", choice(stack[card]))
if answer == w:
print("Correct!")
else:
print("Wrong")
'answer = input("对应的单词是什么",choice(stack[card]))'行不工作,并且返回错误"元组对象不可调用"。我要改变什么?
输入函数最多接受一个参数。你正在经过2。相反,使用字符串格式方法格式化提示,然后将其传递给输入。此外,对choice的调用应该接受可供选择的项目列表,而不是列表中的特定项目,card是一个元组,而不是索引。在你继续之前,你需要回过头来,确保你了解了更多的基础知识。
(word, definition) = choice(stack)
prompt = 'What is the word that corresponds with "{}"'.format(defintion)
answer = input(prompt)
if answer == word:
print("Correct!")
else:
print("Wrong")