資源簡介
關于Python的小例子,適合Python初學者
代碼片段和文件信息
import?random
def?roll_dice(numbers=3?points=None):????
????print(‘<<<<>>>>‘)
????if?points?is?None:????????
????????points?=?[]
????while?numbers?>?0:???????
????????point?=?random.randrange(17)
????????points.append(point)
????????numbers?=?numbers?-?1
????return?points?
def?roll_result(total):????
????isBig?=?11?<=?total?<=18
????isSmall?=?3?<=?total?<=10
????if?isBig:????????
????????return?‘Big‘
????elif?isSmall:
????????return?‘Small‘?
def?start_game():???
????amount=1000
????while?amount>0:
????????print(‘<<<<>>>>‘)
????????choices?=?[‘Big‘‘Small‘]
????????your_choice?=?input(‘Big?or?Small?:‘)
????????if?your_choice?not?in?choices:
????????????print(‘Invalid?Words‘)
????????????start_game()
????????else:
????????????bet=int(input(“how?much?you?wanna?bet???-“))
????????????points?=?roll_dice()
????????????total?=?sum(points)
????????????youWin?=?your_choice?==?roll_result(total)?
????????????if?youWin:???????????
????????????????print(‘The?points?are‘points‘You?win?!‘)
????????????????amount+=bet
????????????????print(“you?gained?“+str(bet)+“you?have?“+str(amount)+“?now.“)????????????????
????????????else:
????????????????print(‘The?points?are‘points‘You?lose?!‘)
????????????????amount-=bet
????????????????print(“you?lost?“+str(bet)+“you?have?“+str(amount)+“?now.“)
????else:
????????print(“GAME?OVER!“)
start_game()
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1429??2021-01-27?20:33??Python例子\bet.py
?????文件????????466??2020-11-18?17:36??Python例子\GUI圖形.py
?????文件????????244??2020-11-22?11:25??Python例子\print_money.py
?????文件????????324??2020-11-21?10:23??Python例子\九九乘法表.py
?????文件????????188??2020-11-21?11:13??Python例子\倒計時顯示.py
?????文件????????454??2021-01-27?18:20??Python例子\寫入文本.py
?????文件????????156??2021-01-27?18:15??Python例子\創建文本文檔.py
?????文件????????416??2020-12-02?14:05??Python例子\判斷是一年中的第幾天.py
?????文件????????270??2021-01-13?19:40??Python例子\求π.py
?????文件???????1189??2021-01-21?20:33??Python例子\猜大小.py
?????文件????????161??2020-12-02?14:30??Python例子\裴波那契數列.py
?????文件????????332??2021-01-21?19:43??Python例子\計算復利.py
?????文件????????105??2021-01-10?15:27??Python例子\調用函數.py
?????文件????????935??2020-11-21?18:05??Python例子\輸入名字并輸出.py
?????文件????????105??2020-12-03?08:36??Python例子\逆序輸出.py
?????文件????????358??2020-11-24?13:11??Python例子\逢7的倍數跳過.py
?????目錄??????????0??2021-03-02?16:34??Python例子
-----------?---------??----------?-----??----
?????????????????7132????????????????????17
評論
共有 條評論