Craps赌博游戏
##假设玩家有1000元赌注

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
from random import randint
money = 1000
while money > 0:
print('你的总资产为:', money)
needs_go_on = False
while True:
debt = int(input('请下注: '))
if 0 < debt <= money:
break
first = randint(1, 6) + randint(1, 6)
print('玩家摇出了%d点' % first)
if first == 7 or first == 11:
print('玩家胜利')
money += debt
elif first == 2 or first == 3 or first == 12:
print('庄家胜利')
money -= debt
else:
needs_go_on = True
while needs_go_on:
needs_go_on = False
current = randint(1, 6) + randint(1, 6)
print('玩家再次掷骰子:%d点' % current)
if current == 7:
print('庄家胜利')
money -= debt
elif current == first:
print('玩家胜利')
money += debt
else:
needs_go_on = True
print('你破产了,游戏结束!')

空格语法虽然看着很工整,但Ctrl+Alt+L太频繁,不过少敲了2次键盘({})。

看习惯了{},一时还真不习惯。