PYTHON / BUILD A PLAYABLE DICE GAME · STEP 1 OF 6
Build a playable dice game
Checking your account…
GUIDED PRACTICE
Build a playable dice game
Follow the current step and use Run & check this step. Your code carries forward.
Your code stays in one editor through every step. Word wrap is enabled.
Step 1 of 6
Import random
The game needs randint to draw integer values. The module is imported before any draws.
Your task
Make the next small change, keeping the working code from the previous step.
To pass this step:
- Add
import random.
Press the play button labeled Run & check this step below the editor to run your code and see your check results.
Your editor is opening.
Each step builds on the last. Finish the current step before opening the next one; your code stays with you.
This is one possible solution. Compare it with your own code; opening it does not replace your work or complete a step.
import randomimport random
user_input = input("Do you want to roll the dice? (y/n) ").strip().lower()import random
user_input = input("Do you want to roll the dice? (y/n) ").strip().lower()
if user_input == "y":
die1 = random.randint(1, 6)
print(die1)import random
user_input = input("Do you want to roll the dice? (y/n) ").strip().lower()
if user_input == "y":
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
print(f"You rolled a {die1} and a {die2}.")import random
while True:
user_input = input("Do you want to roll the dice? (y/n) ").strip().lower()
if user_input == "y":
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
print(f"You rolled a {die1} and a {die2}.")
elif user_input == "n":
print("Goodbye")
break
else:
breakimport random
while True:
user_input = input("Do you want to roll the dice? (y/n) ").strip().lower()
if user_input == "y":
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
print(f"You rolled a {die1} and a {die2}.")
elif user_input == "n":
print("Goodbye")
break
else:
print("Please enter 'y' or 'n'.")Code and completed steps save in this browser when signed out. Sign in to save across devices.
Choose the copy to continue. Your account work will only be replaced if you choose this device.
Ready to checkRun the checks to see your results here.