Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CREATE A PROGRAM IN PYTHON !!!! You are playing a dice game with your friends. E

ID: 3603760 • Letter: C

Question

CREATE A PROGRAM IN PYTHON !!!!

You are playing a dice game with your friends. Each player rolls the dice eight times. The best possible score would be to roll all the numbers 1 through 6 within those eight dice rolls. You must roll a 1 to start the sequence otherwise you will lose that round.

This program must contain 2 loops and an IF structure.

This program is an example of sequencing.

THE PROGRAM SHOULD DISPLAY:

input () # Enter the number of players

input () # Enter the number of rounds

# You will need to generate a random number between 1 and 6 for each of the eight dice rolls.

First Player

You have rolled......

1 3 3 4 2 1 3 1 #Randomly generated sample

----------------------

Verifying Sequence......

dice roll 1 = 1

dice roll 4 = 2

dice roll 2 = 3

dice roll 4 = 4

----------------------

Score = 4

Total Score = ? #Depending on how many rounds

Second Player

You have rolled......

2 3 3 5 2 1 3 5 #Randomly generated sample

----------------------

Verifying Sequence......

dice roll 6 = 1

dice roll 1 = 2

dice roll 2 = 3

----------------------

Score = 3

Total Score = ? #Depending on how many rounds

Third Player

You have rolled......

2 6 3 5 2 4 3 5 #Randomly generated sample

----------------------

Verifying Sequence......

0 points this round

----------------------

Score = 0

Total Score = ? #Depending on how many rounds

First Player has won the game ! #This is an example of only one round played  

Explanation / Answer

This program will need some variables to represent the numbers showing on each die and the total of the two dice. Since these numbers are all integers, we can use three variables of type int. I'll call the variables die1, die2, and roll. The program begins by declaring the variables:

In the actual program, of course, I've added a comment to explain the purpose of each variable. The values of die1 and die2 can be computed using the expression given in the exercise:

Note that even though the expressions on the right-hand sides of these assignment statements are the same, the values can be different because the function Math.random() can return different values when it is called twice.

We can then compute roll = die1 + die2 and use three System.out.println statements to display the three lines of output:

Note that I've chosen to use the concatenation operator, +, to append the value of die1 onto the string "The first die comes up". Alternatively, I could use two output statements:

Yet another possibility is to use System.out.printf:

I'll also note that I could get away without the variable roll, since I could output the value of the expression die1 + die2 directly:

However, it's generally better style to have a meaningful name for a quantity. By the way, the parentheses around (die1 + die2) are essential because of the precedence rules for the + operator. You might try to experiment with leaving them out and see what happens.

The Solution

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote