In: Computer Science
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.
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.