Defining Two Objects Differently Using One Using Input

28 views Asked by At

Is there a way to define two objects but with one user input? To go deeper, there will be multiple preset dictionaries and I want to ask the user to identify which dictionary they want to use. Then two objects will be set using the input, one will be set to the input as a string (the name of the dictionary) and the other will be set to the dictionary itself.

Barney = {"Height": 100, "Weight": 200, "Hobby", "Fishing"}

input("Who do you want to talk to?")
PersonName=input
PersonDict=input{}
print(PersonName, ":about:", PersonDict)
Who do you want to talk to?  *Barney*
Barney :about: {"Height": 100, "Weight": 200, "Hobby", "Fishing"}
1

There are 1 answers

0
John Gordon On

Make a nested dictionary, where the outer level key is the person's name.

people = {
    "Barney": {"Height": 100, "Weight": 200, "Hobby", "Fishing"},
    "Fred": {"Height": 192, "Weight": 157, "Hobby", "Drinking"},
}

name = input("Who do you want to talk to? ")
print(name, ":about:", people[name])