title: Python program that runs a game of pig with a human player and the computer
body: <p>So in a nutshell, who goes first is decided randomly. When the human players turn does come up, he/she has the option to either hold or roll. If he chooses to roll, a dice is rolled and the values are added(to turn_score) till it is >20 after which it is the computers turn. </p>
  
  <p>The turn score is added to the final score after every turn. If a 1 rolls up, the turn score becomes 0(the final does NOT change). </p>
  
  <p>Any advice on  where I am going wrong with this one?</p>
  
  <pre><code>import random
  def roll_dice():
      return random.randint(1,6)
  
  players = ['Player One', 'Player Two']
  scores = {'Player One': 0, 'Player Two': 0}
  random.shuffle(players)
  
  while True:
      for i in players:
          if i == 'Player One':
              choice = input("Roll(r) or Hold(h)?: ")
              turn_score = 0
              final_score = 0
              if (choice=='r'):
                  while(turn_score&lt;=20):
                      dice_value = roll_dice()
                      turn_score += dice_value
                      if (dice_value==1):
                          turn_score = 0
                          print("-rolled a ",dice_value)
                          print("Pigged out!")
                          break
                      print("Turn score is: ",turn_score)
                      final_score += turn_score
                      print("Your final score is: ",final_score)
                      if (final_score&gt;100):
                          break
          else:
              turn_score=0
              print("It is " +  str(i) + "'s turn.")
              while(turn_score&lt;20):
                  dice_value = roll_dice()
                  if (dice_value==1):
                      turn_score = 0
                      scores[i] +=0
                      print("- rolled a ",dice_value)
                      print("Pigged out!")
                      break
                  else:
                      turn_score+=dice_value
                      print("-rolled a ",dice_value)
          scores[i] += turn_score
          print("Turn score is: ",turn_score)
          print('{} score: {} {} score: {}'.format(players[0], scores[players[0]], players[1], scores[players[1]]))
          if scores[i]&gt;100:
              break
      if scores[i]&gt;100:
          break
  
  winner = [winner for winner in scores if scores[winner] == max(scores.values())]
  print(str(winner) + " is the winner!")`
  </code></pre>
  
  <p>Here is what I am getting as an output:</p>
  
  <pre><code>It is Player Twos turn.
  -rolled a  3
  -rolled a  5
  -rolled a  5
  -rolled a  5
  -rolled a  4
  Turn score is:  22
  Player Two score: 22 Player One score: 0
  Roll(r) or Hold(h)?: h
  It is Player Twos turn.
  - rolled a  1
  Pigged out!
  Turn score is:  0
  Player Two score: 22 Player One score: 0
  Roll(r) or Hold(h)?: r
  Turn score is:  3
  Your final score is:  3
  Turn score is:  5
  Your final score is:  8
  Turn score is:  9
  Your final score is:  17
  Turn score is:  13
  Your final score is:  30
  Turn score is:  16
  Your final score is:  46
  Turn score is:  19
  Your final score is:  65
  -rolled a  1
  Pigged out!
  It is Player Twos turn.
  - rolled a  1
  Pigged out!
  Turn score is:  0
  Player Two score: 22 Player One score: 0
  Roll(r) or Hold(h)?:
  </code></pre>