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