-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcraps.py
More file actions
43 lines (35 loc) · 1002 Bytes
/
craps.py
File metadata and controls
43 lines (35 loc) · 1002 Bytes
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
import random as r
outcom = {7: "WON", 11: "WON", 2:"LOST", 3:"LOST", 12: "LOST"}
def roll_dice():
"""
Roll the sum of two dice
"""
dice_1 = r.randint(1,6)
dice_2 = r.randint(1,6)
dice_sum = dice_1 + dice_2
print("played rolled" + " " + str(dice_1) +" "+ str(dice_2) + " = " + str(dice_sum))
return dice_sum
def main(dice_sum):
"""
Determines whether the player is a winner or loser based on the sum of two dice
"""
game_status = "CONTINUE"
mypoint = 0
for key , value in outcom.items():
if (key == dice_sum):
game_status = value
mypoint = dice_sum
while (game_status == "CONTINUE"):
roll = roll_dice()
if roll == mypoint:
game_status = "WON"
break
elif roll == 7:
game_status = "LOST"
break
if game_status == "WON":
print ("player Is Wins")
else:
print("player Is Loses")
sum_score = roll_dice()
main(sum_score)