Search code examples
pythonpython-3.xdice

I am trying to make my dice game so that instead of it changing one of numbers of the dice each roll it changes all of them


So the problem is in line 9 through 32. It outputs say "3 0 0" then "3 4 0" then "3 4 6". Instead it should say "3 4 6" then it could be "6 1 2". I know it's to do with the numRolled variable and the way it loops with that but I cannot think where else to put it.

I've tried putting numRolled = 0 at the end of the "for i in range(3)" but that just makes it so that only the first number changes. I've tried making the numbers into a single variable list but I am not really confident with coding in lists so I decided to go with what I have here.

def DiceGame():

  numRolled = 1
  RunScore = 0
  Roll1 = 0
  Roll2 = 0
  Roll3 = 0
  #rolls the 3 dice 100 times
  for x in range(100): 
    numRolled = 0
    #rolls the 3 dice
    for i in range(3):
      score = rdm.randint(1,6)
      numRolled += 1
      #assigns score to each die
      if numRolled == 1:
        Roll1 = score
      if numRolled == 2:
        Roll2 = score
      if numRolled == 3:
        Roll3 = score

      if Roll1 == Roll2 and Roll1 == Roll3:
        RunScore += 100
      else:
        DiceTot = Roll1 + Roll2 + Roll3
      # If Total of Die MOD 2 == 0 then Running score += Dice Total 
      if DiceTot % 2 == 0:
        RunScore += DiceTot
      else:
        RunScore -= DiceTot  
      print(Roll1, Roll2, Roll3)
      print(RunScore)

As I said above, it outputs say "3 0 0" then "3 4 0" then "3 4 6". Instead it should say "3 4 6" then it could be "6 1 2"


Solution

  • change this

    def game: 
        forlopp:
            forloop:
                print()
                print()
    

    to this

    def game: 
        forlopp:
            forloop:
            print()
            print()