# imports
from datetime import datetime
from random import randint
# variables
world = '🌍🌎🌏'
python = 'Python 🐍'
fire = '🔥'
# Function definitions
def roll_dice():
roll = randint(1, 6)
print(f'You rolled a {roll} {fire * roll}')
# 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()}')
roll_dice()
Project 1 — Step 13 of 16
⭐ Step 13 — Multiply strings
➡️ Print one 🔥 for every point on the dice.
In Python you can multiply a word (or an emoji) by a number
and it repeats that many times! '🔥' * 4 becomes '🔥🔥🔥🔥'.
✏️ What to type
Replace the inside of roll_dice() with two lines:
roll = randint(1, 6)
print(f'You rolled a {roll} {fire * roll}')
The first line saves the random number into a box called roll.
The second line prints the number AND that many fire emojis.
# imports
from datetime import datetime
from random import randint
# variables
world = '🌍🌎🌏'
python = 'Python 🐍'
fire = '🔥'
# Function definitions
def roll_dice():
print(f'You rolled a {randint(1, 6)}')
# 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()}')
roll_dice()
Tap ▶ Run. You should see something like:
You rolled a 4 🔥🔥🔥🔥
The number of fires matches the dice roll. 🔥
💡 If you get a red error
Make sure both lines inside the function are pushed in by 4 spaces (use Tab).
Adapted from Raspberry Pi Foundation — Hello World under CC BY-SA 4.0.