from tkinter import Tk,simpledialog,messagebox
print("Ask the Expert - Capital Cities of the World")
root=Tk()
root.withdraw()
the_world={}
def read():
with open("C:\\Users\\Administrator\\Desktop\\Dev-C++\\请教专家\\capital_data.txt")as file:
for line in file:
line=line.rstrip("\n")
country,city=line.split("/")
the_world[country]=city
def write(country,city):
with open("C:\\Users\\Administrator\\Desktop\\Dev-C++\\请教专家\\capital_data.txt","a")as file:
file.write('\n'+country+'/'+city)
read()
while 1:
q_c=simpledialog.askstring("Country","Type the name of a country: ")
q_c=q_c.capitalize()
if q_c in the_world:
re=the_world[q_c]
messagebox.showinfo("Answer","The capital city of "+q_c+" is "+re+'!')
else:
new=simpledialog.askstring("Teach me","I don\'t know! "+"What is the capital city of "+q_c+'?')
the_world[q_c]=new
write(q_c,new)
root.mainloop()
请教专家【PY】
最新推荐文章于 2024-04-30 16:17:31 发布