Question

In: Computer Science

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 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

Please look at my code and in case of indentation issues check the screenshots.

---------------main.py-----------------

import random

def roll_die():                                       #rolling of a virtual die. Returns a single random integer between 1 and 6 (inclusive).
   return random.randint(1, 6)


def main():
   dice_value_1 = roll_die()                                       #Call the roll_die function twice to get values for the round
   dice_value_2 = roll_die()
   sum_of_two = dice_value_1 + dice_value_2
   print("You rolled ", dice_value_1, "+", dice_value_2, "= ", sum_of_two)   #print the dice values, and their sum

   if sum_of_two == 7 or sum_of_two == 11:                        #If the sum is 7 or 11 on the first roll, you win.
       print("YOU WIN")
       return
   elif sum_of_two == 2 or sum_of_two == 3 or sum_of_two == 12:    #If the sum is 2, 3 or 12 on the first roll you lose   
       print("YOU LOSE")
       return
   else:
       point = sum_of_two                      #If the sum is 4, 5, 6, 8, 9 or 10 on the first roll, that sum becomes your “point.”
       print("Point is", point)
       sum_of_two = 0
       while sum_of_two != 7 and sum_of_two != point: #win by rolling the dice until you “make your point”, or lose by getting 7
           dice_value_1 = roll_die()                               #Call the roll_die function twice to get values for the round
           dice_value_2 = roll_die()
           sum_of_two = dice_value_1 + dice_value_2  
           print("You rolled ", dice_value_1, "+", dice_value_2, "= ", sum_of_two) #print the dice values, and their sum
       if sum_of_two == 7:                    #lose by getting 7
           print("YOU LOSE")
           return
       if sum_of_two == point:                #win by getting point
           print("YOU WIN")
           return   
main()

--------------Screenshots--------------------

------------------Output-----------------

--------------------------------------------------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs down.
Please Do comment if you need any clarification.
I will surely help you.


Related Solutions

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 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
Roll two fair dice. Each die has six faces. A. Let A be the event that...
Roll two fair dice. Each die has six faces. A. Let A be the event that either a 3 or 4 is rolled first followed by an odd number. P(A) =  Round your answer to two decimal places. B. Let B be the event that the sum of the two dice is at most 7. P(B) =  Round your answer to two decimal places. C. Are A and B mutually exclusive events? (Yes or No) D. Are A and B independent or...
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.
Four identical six-sided dice, each with faces marked 1 to 6 are rolled 200 times. At...
Four identical six-sided dice, each with faces marked 1 to 6 are rolled 200 times. At each rolling, a record is made of the number of dies whose score on the uppermost face is even. The result is as follows. No. Of even score, Xi Frequency, fi 0 10 1 41 2 70 3 57 4 22 a) Explain why the binomial model might describe the distribution of X. b) Perform the ?2 -test at ? = 0.05 to test...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT