仇思隽,红色官神,勃力得
python是一个脚本语言,被解释器解释执行。它的发布方式:
[root@localhost ~]# pip install pyinstaller
# -*- coding:utf-8 -*-
import random
import time
def enter_stake(current_money):
'''输入小于结余的赌资及翻倍率,未考虑输入type错误的情况'''
stake = int(input('how much you wanna bet?(such as 1000):'))
rate = int(input("what multiplier do you want?你想翻几倍?(such as 2):"))
small_compare = current_money < stake * rate
while small_compare == true:
stake = int(input('you has not so much money ${}!how much you wanna bet?(such as 1000):'.format(stake * rate)))
rate = int(input("what multiplier do you want?你想翻几倍?(such as 2):"))
small_compare = current_money < stake * rate
return stake,rate
def roll_dice(times = 3):
'''摇骰子'''
print('<<<<<<<<<< roll the dice! >>>>>>>>>>')
points_list = []
while times > 0:
number = random.randrange(1,7)
points_list.append(number)
times -= 1
return points_list
def roll_result(total):
'''判断是大是小'''
is_big = 11 <= total <= 18
is_small = 3 <= total <= 10
if is_small:
return 'small'
elif is_big:
return 'big'
def settlement(boo,points_list,current_money,stake = 1000,rate = 1):
'''结余'''
increase = stake * rate
if boo:
current_money += increase
print('the points are ' + str(points_list) + ' .you win!')
print('you gained $' + str(increase) + '.you have $' + str(current_money) + ' now.' )
else:
current_money -= increase
print('the points are ' + str(points_list) + ' .you lose!')
print('you lost $' + str(increase) + '.you have $' + str(current_money) + ' now.' )
return current_money
def sleep_second(seconds=1):
'''休眠'''
time.sleep(seconds)
def start_game():
'''开始猜大小的游戏'''
current_money = 1000
print('you have ${} now.'.format(current_money))
while current_money > 0:
print('<<<<<<<<<<<<<<<<<<<< game starts! >>>>>>>>>>>>>>>>>>>>')
your_choice = input("big or small: ")
choices = ['big', 'small']
if your_choice in choices:
stake, rate = enter_stake(current_money)
points_list = roll_dice()
total = sum(points_list)
actual_result = roll_result(total)
boo = your_choice == actual_result
current_money = settlement(boo,points_list,current_money,stake,rate)
else:
print('invalid input!')
else:
sleep_second()
print('game over!')
sleep_second(2)
if __name__ == '__main__':
start_game()
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
python求numpy中array按列非零元素的平均值案例
网友评论