Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Player:
- def __init__(self, number=0):
- self.number = number
- self.attemts = 0
- self.history_of_rolls=[]
- def dice_roll(self):
- from random import randrange
- dice = randrange(1 ,7)
- self.history_of_rolls.append(dice)
- return dice
- def __repr__(self):
- message = f"Player {self.number + 1} history: \n {self.history_of_rolls}"
- return message
- if __name__ == "__main__":
- participants = 4
- list_of_players = []
- for _ in range (0, participants):
- the_player=Player(_)
- attempt = 0
- while attempt != 6:
- attempt = the_player.dice_roll()
- list_of_players.append(the_player)
- min_attempts = len(list_of_players[0].history_of_rolls)
- winner = 0
- max_attempts = 0
- looser = 0
- for single_player in list_of_players:
- if len(single_player.history_of_rolls)<min_attempts:
- min_attempts = len(single_player.history_of_rolls)
- winner = single_player.number
- if len(single_player.history_of_rolls)>max_attempts:
- max_attempts = len(single_player.history_of_rolls)
- looser = single_player.number
- print(single_player.__repr__())
- print(f"Winner is player {winner + 1}. He needs {min_attempts} attempts to throw a six.")
- print(f"Winning series is {list_of_players[winner].history_of_rolls}")
- print("Congratulations !")
- print(f"Looser is player {looser + 1}. He needs {max_attempts} attempts to throw a six.")
- print(f"Black series is {list_of_players[looser].history_of_rolls}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement