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(“对应的单词是什么,”选择(堆栈[卡片]))'行不起作用,并返回错误“元组对象不可调用”。我有什么改变?
答案 0 :(得分:2)
输入函数最多需要一个参数。您正在传递2.而是使用字符串格式方法格式化您的提示,然后将其传递给输入。此外,选择调用应该选择项目列表,而不是列表中的特定项目,卡片是元组,而不是索引。在继续之前,你需要回过头来确保你对基础知识有更多了解。
(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")