

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
The whole point of type hints is that they should match what the code actually does. If a function returns a string, its return type hint should also be str.
def get_quest_reward(quest_name: str, quest_xp: int) -> str:
return f"You've earned {quest_xp} XP for completing the {quest_name} quest!"
An incorrect type hint is confusing at best, even if you can still force the Python code to run. Your editor will likely also warn you, with something like a red squiggly line, if a function returns a value that doesn't match its return type hint.
Fantasy Quest's greeting function works, but its return type hint is wrong.
Fix the return type hint on get_greeting by changing it to str. Don't change the function body.
Notice that the squiggly warning goes away when the types match up!