Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # There are two players John and Mary.
- # Each of them has 5 normal dice with 6 sides and beginning with 1001 points.
- # Game works on rounds. First playing Mary, after then John.
- # Every time when player draw his dice, from his start points extracts dice result and print them.
- # The Game Wins player which total points is exactly 0.
- # If some round player points has negative value, on next round this player must adding (not extract) dice result to his points.
- from random import randint
- def draw_dice(dice_sides, number_dice):
- draw_result = 0
- for dice in range(number_dice):
- draw_result += randint(1, dice_sides)
- return draw_result
- mary_points = 1001
- john_points = 1001
- is_mary_turn = True
- while True:
- if is_mary_turn and (mary_points == 0 or john_points == 0):
- if mary_points == 0:
- print("\nMary Wins!")
- else:
- print("\nJohn Wins!")
- break
- dice_result = draw_dice(6, 5)
- if is_mary_turn:
- print('Mary draw {0}' .format(dice_result))
- if mary_points > 0:
- mary_points -= dice_result
- else:
- mary_points += dice_result
- print('Mary now have {0} points.' .format(mary_points))
- else:
- print('John draw {0}' .format(dice_result))
- if john_points > 0:
- john_points -= dice_result
- else:
- john_points += dice_result
- print('John now have {0} points.' .format(john_points))
- is_mary_turn = not is_mary_turn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement