python搖骰子游戲小案例
小案例:
import random
#充值函式
def topup():
global money
n = input('充值金額(100元等于30個金幣充值金額不低于100元):')
num = int(n)
if(num % 100 == 0 and num > 0):
money = (num//100)*30
print("*"*10+"充值成功"+'*'*10)
print('當前賬戶:{}---您當前金幣剩余:{}枚'.format(username, money))
#搖色子函式
def debit():
global money
first = random.randint(1, 6)
last = random.randint(1, 6)
money -= 2
print('系統已經洗牌完畢!!!')
guress = input('請您輸入大小(大/小)')
if(((first+last > 6) and guress == '大') or ((first+last <= 6) and guress == '小')):
print('恭喜您本局游戲勝利!本局游戲獎勵4和游戲金幣')
money += 6
print('當前賬戶:{}---您當前金幣剩余:{}枚'.format(username, money))
answer = input('是否繼續游戲嗎?繼續游戲需要扣除2枚金幣(y/n)')
debit()
else:
print('很遺憾本局游戲失敗@-@')
print('當前賬戶:{}---您當前金幣剩余:{}枚'.format(username, money))
answer = input('是否繼續游戲嗎?繼續游戲需要扣除2枚金幣(y/n)')
if(answer != 'y' or money < 2):
print('........退出游戲...........')
else:
debit()
username = input('請輸入您的賬號:')
money = 4
answer = input('您確定進入游戲嗎(y/n)')
if (answer == 'y'):
if money < 2:
answer = input(
"當前賬戶:{}---您當前金幣剩余:{}枚是否充值(y/n)".format(username, money))
if(answer == 'y'):
topup()
debit()
else:
if(answer == 'y'):
print('歡迎{}進入游戲'.format(username))
while True:
debit()
注:學了一點點python寫的小案例
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/174561.html
標籤:其他
上一篇:華為 華三 思科常用命令
下一篇:談談讀書自由與財富自由
