2 回答
TA贡献1847条经验 获得超7个赞
而不是line.split(","),尝试类似的东西line = line.split(","),因为我认为该split()函数返回列表,并且不会修改字符串本身。
TA贡献1851条经验 获得超5个赞
试试这个:
def main():
with open ("Spanish Words Randomized.txt", "r") as fin :
# read the whole file, stripping EOL and filtering the empty lines
text = [line.strip() for line in fin.readlines() if len(line) > 1]
for line in text :
q, a = line.split(",") # need to catch the results of the split()
answer = input("What is '" + q + "' in Spanish?:")
if answer == a :
print("correct")
else : # no point to check what we already know
print("It was", a)
main()
添加回答
举报
