Kodewick
Start learning →
Mini challenge←→0 / 80

Phone storage

#069Mini challengeRecursionDicts6 min

Phone storage is a dict: each key is a name, and each value is either a file size (MB, a number) or a folder (another dict like this). Write used_space(folder) to add up how many MB the folder uses. An empty folder is 0.

Examples
used_space({"a.jpg": 3, "Trip": {"b.jpg": 5, "c.mp4": 40}})→48
used_space({})→0
main.py
def used_space(folder):
    total = 0
    for item in folder.values():
        # your code here: if it's a folder, add what it uses; if it's a file, add its size
        pass
    return total
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.