Python赌大小

import random
money = 15
while money >= 5:
    print("您的余额为:", money)
    Y = input('是否继续赌博?【yes/no】:')
    while True: #非法输入无效
        if Y == 'yes' or Y == 'no':
            break
        else:
            Y = input("输入有误,请重新输入【yes/no】...")
    if Y == 'yes':
        large = input("【大/小】:")
        while True:
            if large == '大' or large == '小':
                break
            else:
                large = input("输入有误,请重新输入...【大/小】:")
        numList = [] #用于添加色子的点数
        sum = 0
        for i in range(3):
            numList.append(random.choice(range(1, 7)))
            sum += numList[i] #三个色子点数相加
        if sum < 11:
            print(numList, "%d点小" % sum)
            if large == '小':
                print("恭喜您中了大奖!")
                money += 5
            else:
                print("谢谢惠顾")
                money -= 5
        else:
            print(numList, "%d点大" % sum)
            if large == '大':
                print("恭喜您中了大奖!")
                money += 5
            else:
                print("谢谢惠顾")
                money -= 5
    else:
        print("您的余额为:", money)
        print("谢谢光临,欢迎下次再来!")
        break
else:
    print("您的余额不足,还有money =", money)

猜你喜欢

转载自blog.csdn.net/yihong_li/article/details/81120531