Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何将用户输入永久添加到字典_Python 3.x_File_Input_Raspberry Pi_Fwrite - Fatal编程技术网

Python 3.x 如何将用户输入永久添加到字典

Python 3.x 如何将用户输入永久添加到字典,python-3.x,file,input,raspberry-pi,fwrite,Python 3.x,File,Input,Raspberry Pi,Fwrite,我的问题是:如何更新此脚本,以便在脚本重新启动时,字典将包含一个新条目?如何使用用户输入和附加功能将新团队永久添加到字典中?;]我的英语不是很好 你需要将字典存储在一个文件(或数据库)中,否则一旦程序终止它就会丢失你到目前为止都在尝试什么?我已经尝试过更新功能,写文件,现在我开始考虑附加功能,但最好找比我认为更复杂的人,因为我不知道当字典在文件中或dbfunction append不起作用时如何做相同的操作?如果我在脚本的末尾添加一行,用一个附加条目替换字典内容?否,字典存储在内存中,当程序终止

我的问题是:如何更新此脚本,以便在脚本重新启动时,字典将包含一个新条目?如何使用用户输入和附加功能将新团队永久添加到字典中?;]我的英语不是很好

你需要将字典存储在一个文件(或数据库)中,否则一旦程序终止它就会丢失

你到目前为止都在尝试什么?我已经尝试过更新功能,写文件,现在我开始考虑附加功能,但最好找比我认为更复杂的人,因为我不知道当字典在文件中或dbfunction append不起作用时如何做相同的操作?如果我在脚本的末尾添加一行,用一个附加条目替换字典内容?否,字典存储在内存中,当程序终止时,所使用的空间将被其他程序使用。除非将其存储在文件或数据库中,否则无法保留其值
teams ={ 
    "BARCELONA": "10",
    "ITALY":"11",
    "SPAIN":"9.5"
    }
print()
print("****************************")
print("GROUP GOALS RANKING")
print("****************************")
print(list(teams.keys()))
print("****************************")
name=input("Which team you are interested in:",)
print()
print("Team of {} get {} goals".format(name, teams[name]))
print("****************************")
print()
new=input("which team do you want to add to the ranking? ",)
rating=input("How much goals get? "+ new + "? ")
teams[new] = float(rating)
print()
print("****************************")
print(list(teams.keys()))
print()
print("Ranking updated, bye")