-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject1.py
More file actions
46 lines (36 loc) · 1.26 KB
/
project1.py
File metadata and controls
46 lines (36 loc) · 1.26 KB
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
import random
def roll():
min_value = 1
max_value = 6
roll = random.randint(min_value, max_value)
return roll
while True:
players = input("Enter the number of players (2 - 4): ")
if players.isdigit():
players = int(players)
if 2 <= players <= 4:
break
else:
print("Must be between 2 and 4 players.")
else:
print("Invalid, try again.")
max_score = 50
player_scores = [0 for _ in range(players)]
while max(player_scores) < max_score:
for player_idx in range(players):
print("\nPlayer number", player_idx + 1, "turn has just started.")
current_score = 0
while True:
should_roll = input("Would you like to roll? (y)? ")
if should_roll.lower() != 'y':
break
value = roll()
if value == 1:
print("You rolled a 1! No points this turn.")
break
else:
current_score += value
print("You rolled a", value)
print("Current turn score:", current_score)
player_scores[player_idx] += current_score
print("Your total score is now:", player_scores[player_idx])