import random def point_num(): point1=random.randrange(1,7) point2 = random.randrange(1, 7) point3 = random.randrange(1, 7) point_num_lst=[point1,point2,point3] return point_num_lst def judge(answer1): judge_lst=['Big','Small'] if judge_lst[0]==answer1: judge_lst1 = range(11, 18) elif judge_lst[1]==answer1: judge_lst1 = range(3, 11) return judge_lst1 Base_money=1000 while Base_money > 0: print('--------------Game start-----------------') answer1=input('Big or Small:--') answer2=input('How much you wanna bet?-') print('-------------Roll the Dice-------------') point_num_re=point_num() sum_number=sum(point_num_re) if sum_number in judge(answer1): print('The point is',point_num_re,'you win') Base_money=Base_money+int(answer2) print('you gain',answer2,'you have',Base_money) elif sum_number not in judge(answer1): print('The point is',point_num_re,'you fail') Base_money = Base_money - int(answer2) print('you loss', answer2, 'you have', Base_money)
终于尝试独立写出了一段代码,虽然只有短短的30行,且里面存在许多Bug,但是自豪感还是很强烈的!!!
这是一个关于猜大小的程序,初始金额1000元,目前已知Bug如下,希望以后有能力再改:
1、押注时(输入Big和Small)忽略了用户输入错误引起程序报错。
2、押注金额可能会超过本身的钱数,导致负债
人生苦短,我用Python!!!