Answers for "create nested dictionary with user input in python"

0

create nested dictionary with user input in python

d = {}

d["Person1"] = {}
d["Person2"] = {}
d["Person3"] = {}

d["Person1"]["Name"] = input("Enter person1 name: ")
d["Person1"]["Age"] = int(input("Enter person1 age: "))
d["Person1"]["Occupation"] = input("Enter person1 occupation: ")

d["Person2"]["Name"] = input("Enter person2 name: ")
d["Person2"]["Age"] = int(input("Enter person2 age: "))
d["Person2"]["Occupation"] = input("Enter person2 occupation: ")

d["Person3"]["Name"] = input("Enter person3 name: ")
d["Person3"]["Age"] = int(input("Enter person3 age: "))
d["Person3"]["Occupation"] = input("Enter person3 occupation: ")

print(d)
Posted by: Guest on October-19-2021
0

create nested dictionary with user input in python

d = {}

size = int(input("Enter the size of nested dictionary: "))
for i in range(size):
    
    dict_name = input("Enter the name of child dictionary: ")
    d[dict_name] = {}
    Name = input("Enter name: ")
    Age = input("Enter Age: ")
    d[dict_name]["Name"] = Name
    d[dict_name]["Age"] = Age
    
print(d)
Posted by: Guest on October-19-2021
0

create nested dictionary with user input in python

family = {}
num = int(input("How many child dictionaries do you want to create: "))

for i in range(num):
    Member = input("Enter child dictionary name: ")
    family[Member] = {}
    Name = input("Enter person name: ")
    Age = input("Enter person age: ")
    family[Member]["Name"] = Name
    family[Member]["Age"] = Age

print("_" * 20)
for i in family:
    print("Name",":",family[i]["Name"])
    print("Age",":",family[i]["Age"])
    print("_" * 20)
Posted by: Guest on October-19-2021

Code answers related to "create nested dictionary with user input in python"

Python Answers by Framework

Browse Popular Code Answers by Language