

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Functions
incomplete
2: Function Review
incomplete
3: Multiple Parameters
incomplete
4: Printing vs. Returning
incomplete
5: Where to Declare Functions
incomplete
6: Order of Functions
incomplete
7: Community
incomplete
8: Boots Interview
incomplete
9: Solutions
incomplete
10: None Return
incomplete
11: Multiple Return Values
incomplete
12: Parameters vs. Arguments
incomplete
13: Default Values
incomplete
14: Curse
incomplete
15: The Training Grounds
incomplete
16: Enchant and Attack
incomplete
17: Archmage
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
All functions must be defined before they're used.
You might think this would make structuring Python code hard because the order of the functions needs to be just right. As it turns out, there's a simple trick that makes it super easy.
Most Python developers solve this problem by defining all the functions in their program first, then they call an "entry point" function at the end of the file. That way all of the functions have been read by the Python interpreter before the first one is called.
Conventionally this "entry point" function is usually called main to keep things simple and consistent.
def main():
health = 10
armor = 5
add_armor(health, armor)
def add_armor(h, a):
new_health = h + a
print_health(new_health)
def print_health(new_health):
print(f"The player now has {new_health} health")
# call entrypoint at the end
main()