Oct-01-2019, 03:41 AM

The following program is a simplified version of Yahtzee, using only 3 die, and keeps a running total of your score vs the computer. Can anybody tell me why it is that when a Chance! occurs it isn't giving me the correct total (the sum of the 3 die faces)? Appreciated.

# @author Stephen Dickey from random import randint YAHTZEE = 50 TWO_OF_A_KIND = 25 NUM_DIE_SIDES = 6 die1 = randint(1, NUM_DIE_SIDES) die2 = randint(1, NUM_DIE_SIDES) die3 = randint(1, NUM_DIE_SIDES) die = die1, die2, die3 CHANCE = 0 totalPointsPlayer = 0 totalPointsComputer = 0 count = 0 rollDice = input("Roll the dice (Y or N)? ") while (rollDice.upper() == "Y" and count < 2): die1 = randint(1, NUM_DIE_SIDES) die2 = randint(1, NUM_DIE_SIDES) die3 = randint(1, NUM_DIE_SIDES) CHANCE = die1 + die2 + die3 if count == 0: print("Player rolls: ", die) else: print("Computer rolls: ", die) if count == 0: if (die1 == die2 == die3) : totalPointsPlayer += YAHTZEE print("Yahtzee! (+ %d)" % (YAHTZEE)) elif ((die1 == die2) or (die1 == die3) or (die2 == die3)) : totalPointsPlayer += TWO_OF_A_KIND print("Two of a kind!(+ %d)" % (TWO_OF_A_KIND)) elif ((die1 != die2) and (die1 != die3) and (die2 != die3)) : totalPointsPlayer += CHANCE print("Chance! (+ %d)" % (CHANCE)) else: if (die1 == die2 == die3) : totalPointsComputer += YAHTZEE print("Yahtzee! (+ %d)" % (YAHTZEE)) elif ((die1 == die2) or (die1 == die3) or (die2 == die3)) : totalPointsComputer += TWO_OF_A_KIND print("Two of a kind!(+ %d)" % (TWO_OF_A_KIND)) elif ((die1 != die2) and (die1 != die3) and (die2 != die3)) : totalPointsComputer += CHANCE print("Chance! (+ %d)" % (CHANCE)) print() print("===========================") print("Player total points: %d " % (totalPointsPlayer)) print("Computer total points: %d " % (totalPointsComputer)) print("===========================") print() count = count + 1 if count == 2: rollDice = input("Roll the dice again (Y or N)? ") if (rollDice.upper() == "Y"): count = 0 print()