If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Challenge: 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)).

Code editor

Code files

Output