Question: This is python question: how do I reference two dictionary? If the choice is not CAT, DOG, COW, DEER, and, Bear then I would like

This is python question:

how do I reference two dictionary?

If the choice is not CAT, DOG, COW, DEER, and, Bear then I would like to next which in_test dictionary.

How do I go there?

def mainmenu(): print("what kind of animal account you want to create") print("[1] animal account ") print("[0] failed or Exit") animal = int(input("Enter your choice:")) return animal def animal(): rip_test=dict() rip_test["Name"]=input("Enter name: ") name_test=input("Enter name of test:") print(rip_test) animal_id = dict({"CAT": "brown", "DOG": "Blue", "COW": "White", "DEER": "Red", "Bear": "Black" }) in_test = {"Would changing this password cause issues?": {"Yes": "Rabbit", "No": {"Does changing this password require coordination with activities?": {"Yes": "snake", "No": {"Can this password be rotated automatically?": {"Yes": "python snake", "No": None } } } } } } print(build(in_test)) def build(menu): if len(menu) > 1: raise RuntimeError for q in menu: question = q print(question) choices = {} for value, choice in enumerate(menu[question]): print("\t{}: {}".format(value, choice)) choices[value] = choice print("Enter choice: ") valid_resp = False while not valid_resp: try: user_choice = int(input()) except ValueError: print("invalid response") continue valid_resp = True try: next_entry = menu[question][choices[user_choice]] except KeyError: print("Invalid response") valid_resp = False else: if isinstance(next_entry, dict): return build(next_entry) else: return next_entry # treat = None while treat is None: treat = mainmenu() if treat == 1: animal() elif treat == 0: exit() else: print("Invalid Name.") treat = None exit() 

How do I add this code the above Build function

animal_id = dict({"CAT": "brown", "DOG": "Blue", "COW": "White", "DEER": "Red", "Bear": "Black" }) user_entered_string = input("Enter the user_id: ") user_name = user_entered_string.upper() try: description = animal_id[user_name] except KeyError: print("Not recognize this animal id {}" .format(user_name)) exit(1) print("{} is {}" .format(user_name, description))

I have a code already there, but it's not running correctly. my question is If the choice is not CAT, DOG, COW, DEER, How do I go to in_test (dict)?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!