# imports
from datetime import datetime
# variables
world = '🌍🌎🌏'
python = 'Python 🐍'
fire = '🔥'
# Function definitions
# Put code to run under here
print(f'Hello {world}')
print(f'Welcome to {python}')
print(f'{python} is good at maths!')
print(f'{111111111 * 111111111}')
print(f'The date and time is {datetime.now()}')
Project 1 — Step 9 of 16
⭐ Step 9 — Functions
Functions are little chunks of code that do one job. Once you make a function, you can use it again and again.
Here’s an example:
def add_one_and_one():
x = 1 + 1
print(x)
This function is called add_one_and_one. The two lines inside
it are pushed in (indented) by 4 spaces — that’s how Python
knows those lines belong to the function.
To run the function you call it by name with ():
add_one_and_one()
✏️ What to do
Nothing to add yet — just read the example above. Tap ▶ Run to check your program still works the same as last step.
# imports
from datetime import datetime
# variables
world = '🌍🌎🌏'
python = 'Python 🐍'
fire = '🔥'
# Function definitions
# Put code to run under here
print(f'Hello {world}')
print(f'Welcome to {python}')
print(f'{python} is good at maths!')
print(f'{111111111 * 111111111}')
print(f'The date and time is {datetime.now()}')
🔍 Tip
Next step we’ll write a roll_dice function for our program.
Adapted from Raspberry Pi Foundation — Hello World under CC BY-SA 4.0.