The Recipe
Hoppy is tired of casting the same spells over and over. He wants to bundle them into a single command!
In Python, we use Functions to group code together. You define a function using def.
Defining a Function
# Define the function
def jump():
print("Bend knees...")
print("HOP!")
# Call the function (use it)
jump()
jump()
Your Mission
1
Define
Define a function named greet.
2
Body
Inside the function, print "Hello, World!". Remember to indent!
3
Call
Call the greet() function once.
Suggested SolutionClick to expandClick to collapse
Don't forget the parentheses () and the colon :!
def greet():
print("Hello, World!")
greet()Advanced TipsWant more? Click to expandClick to collapse
Functions can also take inputs (parameters) and give back outputs (return values).
def double(x): return x * 2 result = double(5) # 10
pymain.py
Loading...
Terminal
Terminal
Ready to run...