我正在建立一个简单的“测验程序”。此处代码:
import random
wordList1 = []
wordList2 = []
def wordAdd():
wordNew1 = str(input("Add a word to your wordlist: "))
wordNew2 = str(input("Add the translation to this word: "))
if wordNew1 != "exit":
wordList1.append(wordNew1)
wordAdd()
elif wordNew2 != "exit":
wordList2.append(wordNew2)
wordAdd()
else:
exercise()
def exercise():
q = random.choice(wordList1)
a = wordList2
if q[] == a[]:
print("Correct!")
else:
print("Wrong!")
wordAdd()
我试着检查单词列表1的编号并与单词列表2的编号进行比较。 现在我没想到def练习会起作用,但我找不到让它发挥作用的解决方案。。。 我知道Python中的字典,但我想知道在Python中这样的数组构造是否可行。在
有人能帮我吗?在
提前谢谢!西泽
我玩了一点你的代码。我不确定我是否完全理解你的问题,但我按照我认为需要的方式解决了这个问题。我加了一些评论来说明我做了什么。在
我试图坚持你的基本概念(除了递归),但我重命名了很多东西,使代码更具可读性。在
相关问题 更多 >
编程相关推荐