# # # 写一个摇骰子游戏,要求用户压大小,赔率一赔一。要求:三个骰子,每个骰子的值从1-6,摇大小,每次打印摇出来3个骰子的值。import random
# 判断输入数值是否正确(所有与钱有关的)defincome_money(n):whileTrue:
x =input('请输入%s:'% n)if x.isdigit()isFalse:print('输入有误,请重新输入')continueelse:return x
print('--------游戏开始,欢迎来碰碰运气-----------')
capital =int(income_money('本金'))whileTrue:# 用户猜大小whileTrue:
player_guess =input('\n来试一把手气~''\n1:小,2:大,0:退出游戏;''\n请压大小,输入数字代码,用''/''分隔:')
player_list = player_guess.strip('/').split('/')# print(player_list)if player_guess =='0':print('\n吃喝嫖都是赔,唯有赌博有来回。''\n下次再来~')
exit()else:iflen(player_list)!=3:print('输入有误,请重新输入')continueelse:for i in player_list:ifint(i)notinrange(1,3):print('输入有误,请重新输入')continuebreak# 生成随机数
wager =int(income_money('押注金额'))if capital >= wager:
outcome_list =[random.randint(1,6)for _ inrange(3)]# print(outcome_list)
outcome_for_number =[]for i in outcome_list:if i inrange(1,4):
outcome_for_number.extend('小')else:
outcome_for_number.extend('大')print('你押注的大小为:%s'%player_list)print('实际点数为%s'%outcome_list)print(outcome_for_number)if player_list.count('2')== outcome_for_number.count('大'):print('运气不错')
capital += wager
print('你现在的本金为%s'%capital)else:
capital -= wager
print('这次不对,下次走运~')print('你现在的本金为%s'% capital)else:print('你的本金不足')
exit()