  @ThinOldGoose/

# Dice Games ## No description

Files
• main.py
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
```
```import random
def rollDice():
die1 = random.randint(1,6)
die2 = random.randint(1,6)
return die1 + die2
def diceRacer():
print("Welcome to Dice Racer! The player to reach 100 first wins!")
player1_total = 0
player2_total = 0
roll_count = 0
while True:
input("Hit enter to Roll some Dice.")
dieroll1 = rollDice()
roll_count += 1
player1_total += dieroll1
print("Player 1 rolled a:",dieroll1)

dieroll2 = rollDice()
player2_total += dieroll2
print("Player 2 rolled a:",dieroll2)
print("The score is", player1_total, "to", player2_total)

if player1_total >= 100 or player2_total >= 100:
break

if player1_total > player2_total:
print("Player 1 Wins!!!")
elif player2_total > player1_total:
print("Player 2 a!!!")
elif player1_total == player2_total:
print("It's a Tie!!!")
else:
print("This is mathematically impossible")

def greedyPig():
# This is the helper function to play one turn for one player.
def playTurn(player):
turn_total = 0
turn_over = False
while not turn_over:
roll = random.randint(1,6)
print(player, "rolled a", roll)
if roll == 1:
turn_total = 0
print("You got too greedy!")
turn_over = True
break
else:
turn_total += roll
print("You have earned", turn_total, "points so far")
again = input("Press x to take these points, or press enter to roll again.")
if again == "x":
turn_over = True

return turn_total

#Run the actual gameplay of Greedy Pig
print("Welcome to Greedy pig")
player_list = {"Bob":0, "Eric":0, "Fred":0}
for player in player_list:
score = playTurn(player)
player_list[player] = playTurn(player)
print(player, "earned", score, "points.")
player_list[player] += score
print(player, "now has", player_list[player], "points.\n")

for  player in player_list:
print(player,player_list[player])

valid_choice = False
while valid_choice == False:
print("The following games are available:")
print("(1) Dice Racer")
print("(2) Greedy Pig")
print("(q) Quit")

print("...")
if selection == "q":
print("Goodbye.")
return
elif selection == "1":
diceRacer()
elif selection == "2":
greedyPig()
else:
print("That's not a valid choice")
print("...")

#Down here, you run the actual functions