CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day05/craps.py
Views: 729
1
"""
2
Craps赌博游戏
3
玩家摇两颗色子 如果第一次摇出7点或11点 玩家胜
4
如果摇出2点 3点 12点 庄家胜 其他情况游戏继续
5
玩家再次要色子 如果摇出7点 庄家胜
6
如果摇出第一次摇的点数 玩家胜
7
否则游戏继续 玩家继续摇色子
8
玩家进入游戏时有1000元的赌注 全部输光游戏结束
9
10
Version: 0.1
11
Author: 骆昊
12
Date: 2018-03-02
13
"""
14
from random import randint
15
16
money = 1000
17
while money > 0:
18
print('你的总资产为:', money)
19
needs_go_on = False
20
while True:
21
debt = int(input('请下注: '))
22
if 0 < debt <= money:
23
break
24
first = randint(1, 6) + randint(1, 6)
25
print('玩家摇出了%d点' % first)
26
if first == 7 or first == 11:
27
print('玩家胜!')
28
money += debt
29
elif first == 2 or first == 3 or first == 12:
30
print('庄家胜!')
31
money -= debt
32
else:
33
needs_go_on = True
34
35
while needs_go_on:
36
current = randint(1, 6) + randint(1, 6)
37
print('玩家摇出了%d点' % current)
38
if current == 7:
39
print('庄家胜')
40
money -= debt
41
needs_go_on = False
42
elif current == first:
43
print('玩家胜')
44
money += debt
45
needs_go_on = False
46
47
print('你破产了, 游戏结束!')
48
49