YOUR SAVED CODE-ALONG
Code along: Dice Rolling review
Keep the lesson open on your other screen. Your edits stay in this workspace, separate from the practice activity. Sign in to save and reload a private account draft across devices, or share a snapshot when you need help.
CODE-ALONG / THEATER MODE
Dice Rolling review
ORIGINAL WALKTHROUGH · 05:31
Watch with Rob.
Pause whenever you want to try a change. You can return to the lesson at any time.
You are signed in, but video access needs attention. Check your account access. Your saved work is kept.
Video walkthroughs are included with an active Code Zone membership. The written lesson and practice are free.
Video settings & progress
Your lesson progress
Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.
Start the video to enable typing controls.
YOUR TURN
Code along: Dice Rolling review
Recreate the game from the recording. Pause to type, run your Python program and respond to input prompts. This code-along saves separately from your scored challenge and guided practice.
Load an example, edit it and run it. Word wrap is enabled.
Your check results
Lesson reference
Examples load into this same code-along only after you confirm replacing your code.
Watch the original solution
Try the challenge before reading this review. Watch Rob’s original 5:31 solution recording above. Use theater mode to watch and code side by side, or pop out the editor into its own window. Keep your challenge editor open in another tab to compare your own approach.
Normalize once, then branch
strip removes surrounding whitespace; lower lets Y and y follow the same branch. n exits before any random value is generated. An invalid answer stays inside the loop and requests another choice.
Two dice need two draws
Call randint(1, 6) once for die1 and once for die2. Reusing die1 would make every roll doubles. Both endpoints are possible because randint includes its upper bound.
Extend only after passing
Try y, Y, spaces around an answer, an invalid word, and n on the first prompt. Bonus: count rolls, print dice art or celebrate doubles without changing the required output until the checks pass.
One explained browser version
This is one valid approach. The challenge accepts other implementations that meet its observable game contract. Reading or copying this example does not award a pass or replace your saved work.
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:
print("Please enter 'y' or 'n'.")Build it one step at a time
Prefer learning by typing? Work through short instructions, run the Python code and check each change before continuing. Your guided project saves separately from the challenge below.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)6 steps · Saved work · Instant feedback
See the attached lesson’s comic
