Question

In: Computer Science

Do the following code by using python: ( Thank!) You roll two six-sided dice, each with...

Do the following code by using python: ( Thank!)

You roll two six-sided dice, each with faces containing one, two, three, four, five and six spots, respectively. When the dice come to rest, the sum of the spots on the two upward faces is calculated.

• If the sum is 7 or 11 on the first roll, you win.

• If the sum is 2, 3 or 12 on the first roll (called “Mygame”), you lose (i.e., the “house” wins).

• If the sum is 4, 5, 6, 8, 9 or 10 on the first roll, that sum becomes your “point.”

To win, you must continue rolling the dice until you “make your point” (i.e., roll that same point value). You lose by rolling a 7 before making your point.

Solutions

Expert Solution

The Python code for the given problem is as follows -

import random

point = 0

dice1 = random.randint(1,6)
dice2 = random.randint(1,6)

#After first roll
diceSum = dice1 + dice2
if(diceSum == 7 or diceSum == 11):
    print('You Win!')
elif(diceSum == 2 or diceSum == 3 or diceSum == 12):
    print('You Lose!')
else:
    point = diceSum
    while(True):
        #Roll the dices again and agin
        dice1 = random.randint(1,6)
        dice2 = random.randint(1,6)

        if (dice1+dice2 == point):
            print('You Win')
            break
        if(dice1+dice2 == 7):
            print('You Lose')
            break

Explanation-

  • dice1 and dice2 represent 2 variables that are rolled. They have a random value between 1 and 6.
  • The if and elif statemtns after that check for the first and second conditions.
  • In the else statement we calculate the point value and start a loop
  • In the loop, we roll the dice again and again. We first check if sum equals point value then you become the winner. Else if sum equals 7 then you lose.

OUTPUT Screenshot-

We run the program multiple times and can see the different statements. To be more verbose, you can also print the diceSum value.

If you get multiple times the same value, then print and see the diceSum, which will surely be random.


Related Solutions

Please using python to do the following code: You roll two six-sided dice, each with faces...
Please using python to do the following code: You roll two six-sided dice, each with faces containing one, two, three, four, five and six spots, respectively. When the dice come to rest, the sum of the spots on the two upward faces is calculated. • If the sum is 7 or 11 on the first roll, you win. • If the sum is 2, 3 or 12 on the first roll (called “Mygame”), you lose (i.e., the “house” wins). •...
If you roll two six-sided dice, what is the probability of obtaining the following outcomes? a)2...
If you roll two six-sided dice, what is the probability of obtaining the following outcomes? a)2 or 3 b) 6 and 4 c) At least one 5 d) Two of the same number (two 1s, or two 2s, or two 3s, etc.) e) An even number on both dice f) An even number on at least one die
You roll two six-sided even dice. What is the probability that you get a score of...
You roll two six-sided even dice. What is the probability that you get a score of at least 11? a. 2/11 b. 1/12 c. 1/18 d. 1/6 
 
 You toss a fair coin 3 times in a row. What is the probability of getting at most two heads? a. 3/4 b. 1/4 c. 3/8 d. 7/8
. Three Dice of a Kind Consider the following game: You roll six 6-sided dice d1,…,d6...
. Three Dice of a Kind Consider the following game: You roll six 6-sided dice d1,…,d6 and you win if some number appears 3 or more times. For example, if you roll: (3,3,5,4,6,6) then you lose. If you roll (4,1,3,6,4,4) then you win. What is the probability that you win this game?
You roll TWO six-sided die. Find the probability of each of the following scenarios in fractions....
You roll TWO six-sided die. Find the probability of each of the following scenarios in fractions. 1. P(sum=2) 2. P(sum is less than or equal to 4) 3. P(sum=13) 4. P(product)= 20 (Product means multiply) 5. P(product less than or equal to 12)
You roll TWO six-sided die. Find the probability of each of the following scenarios in fractions....
You roll TWO six-sided die. Find the probability of each of the following scenarios in fractions. 1. P(sum=2) 2. P(sum is less than or equal to 4) 3. P(sum=13) 4. P(product)= 20 (Product means multiply) 5. P(product less than or equal to 12)
You roll a six- sided die. Find the probability of each of the following scenarios a....
You roll a six- sided die. Find the probability of each of the following scenarios a. Rolling a 6 or a number greater than 3 b. Rolling a number less than 5 or an even number c. Rolling a 2 or an odd number
A player pays $ 13 to roll three six-sided balanced dice. If the sum of the...
A player pays $ 13 to roll three six-sided balanced dice. If the sum of the 3 dice is less than 13, then the player will receive a prize of $ 70. Otherwise, you lose the $13. a. Find the expected value of profit.
Suppose you roll three fair six-sided dice and add up the numbers you get. What is...
Suppose you roll three fair six-sided dice and add up the numbers you get. What is the probability that the sum is at least 16?
Consider some 8-sided dice. Roll two of these dice. Let X be the minimum of the...
Consider some 8-sided dice. Roll two of these dice. Let X be the minimum of the two values that appear. Let Y denote the maximum.   a) Find the joint mass p_X,Y (x,y). b) Compute p_X│Y (x│y) in all cases. Express your final answer in terms of a table.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT