Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Create a program that uses a function to simulate the roll of a die. Whenever it s helpful, use functions to split your code into

Create a program that uses a function to simulate the roll of a die. Whenever its helpful, use functions to split your code into other functions.
The program should roll two six-sided dice, add the total of the two
Display the results of the dice values
Also, display a special additional message for rolling certain combinations. Two ones (Snake eyes!), Two sixes (Boxcars!), Two 2s (Ballerina!), Two 4s (Square Pair). You can find websites with these "colorful dice combinations" so feel free to add as many additional named combinations as you would like to.
Write the code to display the title in it's own function
Write the code that generates a value for a single die roll in a function named "roll()". HINT: you'll use the "randint()" function that's part of the "random module" in this function in order to get a random result between 1 and 6 to return.
Write the code to obtain a value for two dice rolls, add them together, and print the results in a function named "roll_dice()". This will be a void function that doesn't return a value.
Lastly, in a main() function, write the code that
Calls the functions to display the title
Ask the user if they want to roll the dice the first time
Loops until the user is ready to call it quits for the night.
Calls the roll_dice() function
Ask the user if they want to roll again
Hint: Near the bottom of the loop you should use the same variable to save the user choice for continuing or not that you initialize prior to a While loop. Doing so will allow you to check a single variable in your While loop statement rather than something more complex.
Using the sample output below be sure to generate spacing between each roll.
Sample input/output:
Dice Roller
Roll the dice? (y/n): y
Die 1: 3
Die 2: 6
Total: 9
Roll again? (y/n): y
Die 1: 1
Die 2: 1
Total: 2
Snake eyes!
Roll again? (y/n): y
Die 1: 6
Die 2: 6
Total: 12
Boxcars!
Roll again? (y/n): n
Bye!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students explore these related Databases questions