Course: Intro to computer science - Python > Unit 4
Lesson 1: Function definitionsChallenge: Trophy case
Instructions
Step 1
Convert to a function
In an online game, players can earn trophies by completing in-game tasks. Daniel wrote the logic for a trophy based on the number of hours played. He needs to run this trophy calculation for hundreds of different players, so he wants to convert it to a function.
- Define a new function called
get_time_trophy()
that takes the number of hours played as a parameter and returns the corresponding trophy name.
You’ll want to move the entire conditional inside the function body. The hours_played
variable should change to a function parameter, and instead of printing the trophy name, the function should return it.
Remember that functions don't execute unless you call them! You can test that your function works by inspecting its result, like print(get_time_trophy(8))
.