Oct-09-2018, 03:47 PM
I am relatively new to Python taking GCSE Computer Science at my school. This is for my programming project. I have to create a dice game that has two players roll two dice and add the scores to the respective player. If the two dice are equal, the code will roll a third die. If the total of the two (or three) dice is even, 10 will be added to the score. If it is odd, 5 will be taken away from the score. The problems I am having is that:
1. The score always displays as 0
2. I'm not sure how to add the score shown to the respective players' totals (p1total, p2total)
I have done some testing and still cannot figure out what I am doing wrong
. Suggestions would be appreciated.
1. The score always displays as 0
2. I'm not sure how to add the score shown to the respective players' totals (p1total, p2total)
I have done some testing and still cannot figure out what I am doing wrong

import random import time roundnum = 0 p1total = 0 p2total = 0 p1wins = 0 p2wins = 0 score = 0 def diceroll(): dice1 = (random.randrange (1,6)) dice2 = (random.randrange (1,6)) score = dice1 + dice2 print("score debug: ", score) if score %2 == 0: score += 10 print("score debug2: ", score) if dice1 == dice2: print("score debug3: ", score) dice3 = (random.randrange (1,6)) score = score + dice3 else: score = score - 5 print("score debug4: ", score) if score < 0: print("score debug5: ", score) score = 0 print("The first die shows", dice1) time.sleep(1) print("The second die shows", dice2) time.sleep(1) if dice1 == dice2: print("These two values are equal, so we will roll a third die.") time.sleep(1) print("The third die shows", dice3) def suddendeath(): time.sleep(1) global winner winner = 0 print("Welcome to Sudden Death!") time.sleep(1) dice1 = (random.randrange (1,6)) print("Player One scored", dice1) time.sleep(1) dice2 = (random.randrange (1,6)) print("Player Two scored", dice2) time.sleep(1) if dice1 > dice2: winner = 1 print("Player One wins!") elif dice2 > dice1: winner = 2 print("Player Two wins!") else: print("The two scores are level! Sudden Death continues!") suddendeath() for i in range (5): roundnum += 1 print ("\nThis is Round", roundnum) #Player One time.sleep(1) print("\nPlayer One, your go...") time.sleep(1) diceroll() print("\nPlayer One, you scored", score) p1total += score #Player Two time.sleep(1) print("\nPlayer Two, your go...") time.sleep(1) diceroll() print("\nPlayer Two, you scored", score) p2total += score #SuddenDeath if p1total == p2total: suddendeath()