-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject1_PigGame.py
More file actions
58 lines (44 loc) · 1.52 KB
/
Project1_PigGame.py
File metadata and controls
58 lines (44 loc) · 1.52 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
47
48
49
50
51
52
53
54
55
56
57
58
# pig game
import random
def roll_dice():
minvalue = 1
maxvalue = 6
roll = random.randint(minvalue, maxvalue)
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 - 4 players.")
else:
print("Invalid, try again.")
max_score = 50
player_scores = [0 for _ in range(players)]
while max(player_scores) < max_score:
for indexes in range(players):
print("\nPlayer number", indexes + 1, "turn has just started!")
print("Your total score is:", player_scores[indexes], "\n")
current_score = 0
while True:
roll = input("Would like to roll again (Enter y for yes)? ")
# if it's other than y loop will break
if roll.lower() != "y":
break
value = roll_dice()
if value == 1:
print("Rolled 1!")
current_score = 0
break
else:
current_score += value
print("You rolled :", value)
print("player's score is:", current_score)
player_scores[indexes] += current_score
print("Total score= ", player_scores[indexes])
max_score = max(player_scores)
winner = player_scores.index(max_score)
print("Player ", winner + 1,
"is the winner with a score of:", max_score)