Skip to content

Commit 216dcdb

Browse files
committed
Fifth project
1 parent dcb8514 commit 216dcdb

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

.idea/workspace.xml

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dice_game.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import random
2+
3+
4+
def roll():
5+
6+
min_value = 1
7+
max_value = 6
8+
roll = random.randint(min_value, max_value)
9+
10+
return roll
11+
12+
13+
while True:
14+
players = input('Enter number of player (2-4): ')
15+
if players.isdigit():
16+
players = int(players)
17+
if 2 <= players <= 4:
18+
break
19+
else:
20+
print('Players must be 2 - 4 ')
21+
else:
22+
print('Invalid try again')
23+
24+
max_score = 50
25+
player_scores = [0 for _ in range(players)]
26+
27+
while max(player_scores) < max_score:
28+
29+
for player_index in range(players):
30+
print('\nPlayer', player_index + 1, 'has just started')
31+
print('Your Total score is:', player_scores[player_index], '\n')
32+
current_score = 0
33+
34+
while True:
35+
should_roll = input('would you like to roll (y)? ')
36+
if should_roll.lower() != 'y':
37+
break
38+
39+
value = roll()
40+
if value == 1:
41+
print('You rolled a 1! Turn done')
42+
current_score = 0
43+
break
44+
else:
45+
current_score += value
46+
print('You rolled a ', value)
47+
48+
print('Your current score is', current_score)
49+
50+
player_scores[player_index] += current_score
51+
print('Your Total score is:', player_scores[player_index])
52+
53+
max_score = max(player_scores)
54+
winning_index = player_scores.index(max_score)
55+
print('Player number', winning_index + 1,
56+
'is the winning with a score of:', max_score)

0 commit comments

Comments
 (0)