-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdice_roll_game.py
61 lines (48 loc) · 2.07 KB
/
dice_roll_game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# ______ ___ _______ _______ ______ _______ ___ ___ _______ _______ __ __ _______
# | | | | | || | | _ | | || | | | | || _ || |_| || |
# | _ || | | || ___| | | || | _ || | | | | ___|| |_| || || ___|
# | | | || | | || |___ | |_||_ | | | || | | | | | __ | || || |___
# | |_| || | | _|| ___| | __ || |_| || |___ | |___ | || || || || ___|
# | || | | |_ | |___ | | | || || || | | |_| || _ || ||_|| || |___
# |______| |___| |_______||_______| |___| |_||_______||_______||_______| |_______||__| |__||_| |_||_______|
# John Omoluabi
# This is a program which allows a group of players to roll a dice in turn.
# The player whose accumulated dice rolls values come to a value greater then 50 wins
import random
def roll():
max_value=6
min_value=1
value=random.randint(min_value, max_value)
return value
# number of players
while True:
players=input("enter the number of players(1-4): ")
if players.isdigit():
players=int(players)
if 1 <= players <=4:
break
else:
print("invalid entry")
max_score=50
player_scores=[0 for _ in range(players)]
while max(player_scores) < max_score:
for player_idx in range(players):
print("***************")
print(f"passed to player {player_idx+1}")
print("***************")
s=0
while True:
should_roll=input("do you want to roll(y)? ")
if should_roll != "y":
break
value=roll()
if value==1 :
print("pass!! you rolled a 1")
break
else:
s+=value
print(f"current score is {s}")
player_scores[player_idx] += s
print(f"total score is {player_scores[player_idx]}")
m=max(player_scores)
print(f"winner is {player_scores.index(m)+1}")