2 回答

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個贊
而不是line.split(",")
,嘗試類似的東西line = line.split(",")
,因?yàn)槲艺J(rèn)為該split()
函數(shù)返回列表,并且不會修改字符串本身。

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超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()
添加回答
舉報(bào)