

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Type Hints
incomplete
2: Basic Types
incomplete
3: Function Parameters
incomplete
4: Return Types
incomplete
5: Fixing Type Hints
incomplete
6: List and Set Hints
incomplete
7: Dictionary Hints
incomplete
8: Tuple Hints
incomplete
9: Specific Container Types
incomplete
10: Nested Types
incomplete
11: Optional Values
incomplete
12: Fix Code With Type Hints
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Dictionaries are container types too, but they map keys to values, so their type hints include both:
item_counts: dict[str, int] = {
"Wooden Arrow": 30,
"Small Amethyst": 2,
}
The first type is for the keys; the second is for the values.
dict[key_type, value_type]
So dict[str, int] means:
Not all types can be used as dictionary keys. The key types that you'll see most often are strings and integers. Dictionary values, on the other hand, can be any type.
Fantasy Quest also tracks how many of each item a character has in their inventory. Add type hints to the get_item_count function.
Don't change the function body.