Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.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 如何将用户输入存储到字典中_Python_Function_Dictionary - Fatal编程技术网

Python 如何将用户输入存储到字典中

Python 如何将用户输入存储到字典中,python,function,dictionary,Python,Function,Dictionary,我需要创建一个函数,该函数接受用户提供的名称和年龄,并将这些值存储在字典中 prompt = "\nWelcome, please enter a name and age" prompt += "\nEnter 'done' when finished. " message = "" while message != 'done': input_name = input("\n name?") inpu

我需要创建一个函数,该函数接受用户提供的名称和年龄,并将这些值存储在字典中

prompt = "\nWelcome, please enter a name and age"
prompt += "\nEnter 'done' when finished. "
message = ""
while message != 'done':
    
input_name = input("\n name?") 
input_age = input("\n age?") 
我不知道怎样把这些词条放到字典里

prompt = "\nWelcome, please enter a name and age"
prompt += "\nEnter 'done' when finished. "
message = ""
while message != 'done':
    
input_name = input("\n name?") 
input_age = input("\n age?") 
不需要函数

dictionary = {}

name = input("name: ")
dictionary[name] = input("age: ")

你试过什么?你用谷歌搜索过如何获取用户输入以及如何分配给字典吗?你的函数需要做的两个步骤?请给出一个预期字典的例子。