🐸

The Recipe

Python Basicspython-basics-31-the-recipe
Reward: 150 XP
|

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 Solution
Click to expand

Don't forget the parentheses () and the colon :!

def greet():
  print("Hello, World!")

greet()
Advanced Tips
Want more? Click to expand

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...