学习python的时候编写的一个小游戏,还挺有趣的。下一步是打算做成GUI界面运行。
import random
def roll_dice ():
points = []
tries = 3
while tries > 0:
input('<<<<<----GAME START---->>>>>\n请按ENTER键开始摇骰子,你还有{}次。'.format(tries))
point = random.randrange(1,7)
points.append(point)
tries = tries -1
print('点数为{}'.format(point))
print("次数已经全部用完。")
result = sum(points)
print("点数之和为{}".format(result))
return result
def roll_result (points):
is_small = 3 <= points <= 10
is_big = 11 <=points <= 18
if is_small:
return 1
if is_big:
return 2
def start_game():
amount = int(input('请输入你的本金:\n'))
while amount > 0:
price = int(input('选择一次下注的金额。'))
chioce = int(input("选择大还是小?\n1:小,2:大\n"))
chioces = [1,2]
if chioce in chioces:
game_dice = roll_dice()
game_result = roll_result(game_dice)
if chioce == game_result:
amount = amount + price
print('恭喜你,猜对了。你赢了。你的账户余额为{}'.format(amount))
else:
amount = amount - price
print("很遗憾,你猜错了。输了。你的账户余额为{}".format(amount))
else:
print("输入错误!")
else:
print("不好意思,你输光了。")
start_game()
start_game()
python初学者,有什么建议和不足请指正。