Question
import random # Import the random module, which we will use to generate random numbers. def roll_dice(): # Define a function called roll_dice that will
import random # Import the random module, which we will use to generate random numbers.
def roll_dice(): # Define a function called roll_dice that will roll two dice and return their sum. """Rolls two dice and returns the sum of the dots on the top faces.""" die1 = random.randint(1, 6) # Generate a random number between 1 and 6 (inclusive) for the first die. die2 = random.randint(1, 6) # Generate a random number between 1 and 6 (inclusive) for the second die. return die1 + die2 # Return the sum of the two dice.
while True: # Enter an infinite loop. play_game = input("Do you want to roll the dice? (y/n): ") # Ask the user if they want to play. if play_game.lower() == "y": # If the user says yes (by typing "y"), continue. total = roll_dice() # Roll the dice and get the total. if total == 2: # If the total is 2, it's snake eyes. print("Snake eyes!") elif total == 12: # If the total is 12, it's boxcars. print("Boxcars!") else: # Otherwise, print the total. print(f"You rolled a total of {total}.") print() # Print a blank line for readability. else: # If the user says no (by typing "n"), break out of the loop. break
HOW DO I GET THIS PROGRAM TO DISPLAY BOTH THE DICE NOT JUST THE TOTAL
EXAMPLE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started