# imports
from datetime import datetime
from random import randint
# variables
world = '🌍🌎🌏'
python = 'Python 🐍'
fire = '🔥'
# Function definitions
def roll_dice():
max = input('How many sides on your dice?:')
print(f'That is a D {max}')
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 14 of 16
⭐ Step 14 — Get input
➡️ Ask the player how many sides they want on the dice.
We use input() to ask the player a question. Whatever they
type goes into a box.
✏️ What to type
At the top of the roll_dice() function (before the
roll = randint(...) line), add two lines:
max = input('How many sides on your dice?:')
print(f'That is a D {max}')
Keep them pushed in by 4 spaces so they stay inside the function.
# 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()
Tap ▶ Run. The program will pause and ask:
How many sides on your dice?:
Type a number like 20 and press Enter. You should see:
That is a D 20
You rolled a 4 🔥🔥🔥🔥
(For now the roll is still 1–6. Next step we’ll fix that.)
Adapted from Raspberry Pi Foundation — Hello World under CC BY-SA 4.0.