目录

python-赌场掷骰子游戏

python 赌场掷骰子游戏

掷骰子是赌场里一种非常流行的游戏。编写这个程序玩这个游戏的变种,如下所示

掷两个骰子。每个骰子有六个面,分别表示值1,2,3,4,5,6.检查两个骰子的和。如果和为2,3,12,你就输了

如果和为7,11,你就赢了;如果和是其他数字(4,5,6,8,9,10),就确定一个点。继续掷骰子,知道只出一个7或

者掷出和刚才相同的点数。如果掷出的是7,你就输了,如果掷出的点数和你前一次掷出的相同,你就赢了。程序扮演

一个单独的玩家

import random

win_list = [7, 11]

lost_list = [2, 3, 12]

continue_list = [4, 5, 6, 8, 9, 10]

def throw_dice():

return random.randint(1, 6)

第一把就赢

def win(point_one, point_two):

summation = point_one + point_two

if summation in win_list:

print(“you rolled “+str(point_one)+”+”+str(point_two)+"="+str(summation))

    return True
else:
    return False

第一把就输

def lost(point_one, point_two):

summation = point_one + point_two

if summation in lost_list:

print(“you rolled “+str(point_one)+”+”+str(point_two)+"="+str(summation))

    return True
else:
    return False

第一把没结果

def game_continue(point_one, point_two):

summation = point_one + point_two

if summation in continue_list:

print(“you rolled " + str(point_one) + “+” + str(point_two) + “=” + str(summation))

print(“point is “+str(summation))

point_one = throw_dice()

point_two = throw_dice()

summation_one = point_two + point_one

while summation != 7 and summation != summation_one:

print(“you rolled " + str(point_one) + “+” + str(point_two) + “=” + str(summation_one))

print(“point is " + str(summation_one))

point_one = throw_dice()

point_two = throw_dice()

summation_one = point_two + point_one

print(“you rolled " + str(point_one) + “+” + str(point_two) + “=” + str(summation_one))

print(“you win”)

def main():

point_one = throw_dice()

point_two = throw_dice()

if win(point_one, point_two):

print(“you win”)

elif lost(point_one, point_two):

print(“you lost”)

else:

game_continue(point_one, point_two)

main()