<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">from random import randrange
import json

file_name = "my_json_file.json"

try:
    with open(file_name, "r") as f:
        animal_dict = json.load(f)
        print("Reading data from file: ", file_name, " succeeded")
except:
    # When is this triggered?
    print("Creating json file: ", file_name, " with animal data, feel free to edit it!")
    animal_dict = { 'tiger': ['claws', 'sharp teeth', 'four legs', 'stripes'],
                    'elephant': ['trunk', 'four legs', 'big ears', 'gray skin'],
                    'human': ['two legs', 'funny looking ears', 'a sense of humor'] }

    with open(file_name, mode='w') as f:
        json.dump(animal_dict, f)


# What is this code doing? Try to use Python documentation if a function is unknown.
animal_list = list(animal_dict.keys())
animal_index = randrange(0, len(animal_list))
animal = animal_list[animal_index]
animal_properties = animal_dict[animal]

print('Welcome to the game: "Guess what I am thinking about"!')

# TODO: write the main game loop
while True:
    # 1. show random hint for the picked animal
    try:
        hint_index = randrange(0, len(animal_properties))
    except ValueError:
        print('I have no further hints.')
        break
    print(animal_properties[hint_index])

    # remove hint from list
    animal_properties.pop(hint_index)

    # 2. get answer from user
    answer = input("What's your guess? ")

    # 3. check if answer is correct or not
    # 4. if it is -&gt; stop, if it is not -&gt; repeat
    if answer == animal:
        print("Congratulations, you made it!\n Thank you for playing")
        break

</pre></body></html>