0 XP
Chapter 3

Functions

Package code into reusable blocks — just like game actions.

Core Concept

Functions are named blocks of code you can call whenever you need them.

Theory

Define a function with def, give it a name, and optionally some inputs (parameters): def greet_player(name): print(f"Welcome, {name}!") greet_player("Alex") # calls the function Functions can also return a value: def calculate_damage(attack, defense): return max(0, attack - defense) dmg = calculate_damage(30, 10) print(f"Damage dealt: {dmg}")

Live Demo — Run & Explore

Try it live
Loading...

Output will appear here…

Exercise 1 / 1

📝 Write a function called `is_game_over` that takes `lives` as a parameter and returns True if lives is 0, else False.

Your solution
Loading...

Output will appear here…

Loops
Lists