Function task3() is a simple dice game that roles a dice ten times. The user wins if they have more than 35 points. The number of points is the sum of all the dice rolls and a bonus of 10 points if exactly two of the dice rolls are ones. Implement your dice game as follows: (1) Print a welcome message (2) Output the result of 10 dice rolls using randint(1,6)–print roll # and dice value as shown below. (3) Sum up the values of rolls 1-10. (4) If two of the rolls were the number 1, then print out "+10 Bonus for snake eyes [1][1]!". Add 10 points to the sum-[Note that more than two "ones" do not get a bonus]. (5) If the final points (including bonus) is greater than 35, the user wins; otherwise, they lose. Print out the appropriate message as shown below. (6) Ask the user to input 'Y' to play again. (7) If the user inputs either 'Y' or 'y', return to (1) and play the game again. Otherwise, the function is done.
Python code. It is just one question.
Need to use Variables and expression, strings, conditional-statements, loops.
Thank you. Ill also put example.
import random
def Task3():
total = 0
while True:
print("Dice Game")
print("Rolling Dice 10 times")
countOnes = 0
for i in range(1,11):
num = random.randint(1,6)
total = total + num
if num == 1:
countOnes = countOnes + 1
print("Roll ", i, ": [", num, "]")
if countOnes == 2:
total = total + 10
if total > 35:
print("Total ", total, " -- OVER 35 POINTS [YOU WIN!]")
else:
print("Total ", total, " -- TOO FEW POINTS [YOU LOSE!]")
ch = input("Enter 'Y' to play again: ")
if ch == 'Y':
continue
else:
break
#Calling function
Task3()
Step by step
Solved in 2 steps with 2 images