我該如何製作它,以便將更改保存到字典中?這將能夠添加一個定義,那麼這將是能夠然後退出仍然保持這一定義製作一個Python程序保存它對自己所做的更改
words = {
"orange": "naranja",
"hello": "hola",
"bye": "adiós",
"red": "rojo",
"blue": "azul",
"yellow": "amarillo",
"purple": "púrpura",
"green": "verde",
"white": "blanco",
"black": "negro",
"Ethan": "Yeet"
}
while 1 == 1:
tt = input("What would you like to translate? (Only write in lowercase and type EXIT to quit) ")
if str(tt) in words:
print(tt + " is " + words.get(tt, "Not in dictionary"))
elif str(tt) == "EXIT":
break
else:
atd = input("Would you like to add " + str(tt) + " to our dictionary? Y/N ")
if atd == "Y" or atd == "y":
d = input("What does it translate to? ")
d = str(d)
tt = str(tt)
words.update({tt: d})
print(tt + " is "+ words.get(tt, "What"))
continue
elif str(atd) == "EXIT":
break
else:
continue
你這是什麼意思,從技術上講,你已經用'words.update({tt:d})'來做這件事。 –
@JohnPerry聽起來像這個問題是關於堅持這些變化的文件。 –
@DavidZ這些也是我的想法,但在這種情況下,他需要閱讀和寫作。 –