

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 2
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
Lists and sets usually hold multiple values of the same type:
inventory: list[str] = ["Black Knight Halberd", "Skull Lantern", "Notched Whip"]
But tuples are a small fixed group of values where each position has its own meaning. Because they're fixed, it's quite common for those values to be of different types. For example, a loot drop might have an item name and a quantity:
drop: tuple[str, int] = ("Garnet Mark", 2)
tuple[str, int] means:
A tuple can have any number of values – though 2 and 3 are the most common. Here's an example representing a character's HP, MP, and stamina:
stats: tuple[int, float, int] = (100, 42.5, 75)
The type hint tuple[int, float, int] tells us this is a three-value tuple with an integer, a float, and another integer.
Fantasy Quest uses loot drops to decide what items the player receives after defeating an enemy in battle. Add type hints to the get_loot_drop function.
Don't change the function body.