Advertisement
dimipan80

Dice Game 1001

Aug 31st, 2015
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. # There are two players John and Mary.
  2. # Each of them has 5 normal dice with 6 sides and beginning with 1001 points.
  3. # Game works on rounds. First playing Mary, after then John.
  4. # Every time when player draw his dice, from his start points extracts dice result and print them.
  5. # The Game Wins player which total points is exactly 0.
  6. # If some round player points has negative value, on next round this player must adding (not extract) dice result to his points.
  7.  
  8. from random import randint
  9.  
  10. def draw_dice(dice_sides, number_dice):
  11.     draw_result = 0
  12.     for dice in range(number_dice):
  13.         draw_result += randint(1, dice_sides)
  14.  
  15.     return draw_result
  16.  
  17. mary_points = 1001
  18. john_points = 1001
  19. is_mary_turn = True
  20.  
  21. while True:
  22.     if is_mary_turn and (mary_points == 0 or john_points == 0):
  23.         if mary_points == 0:
  24.             print("\nMary Wins!")
  25.         else:
  26.             print("\nJohn Wins!")
  27.         break
  28.  
  29.     dice_result = draw_dice(6, 5)    
  30.     if is_mary_turn:
  31.         print('Mary draw {0}' .format(dice_result))
  32.        
  33.         if mary_points > 0:
  34.             mary_points -= dice_result
  35.         else:
  36.             mary_points += dice_result
  37.  
  38.         print('Mary now have {0} points.' .format(mary_points))
  39.        
  40.     else:
  41.         print('John draw {0}' .format(dice_result))
  42.        
  43.         if john_points > 0:
  44.             john_points -= dice_result
  45.         else:
  46.             john_points += dice_result
  47.  
  48.         print('John now have {0} points.' .format(john_points))
  49.      
  50.     is_mary_turn = not is_mary_turn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement