|
发表于 2020-2-24 22:22:51
|
显示全部楼层
本帖最后由 uglybeauty 于 2020-2-24 22:25 编辑
第五章综合练习题作业分享
import random
def roll_dice(numbers=3, points=[]):
print('<<<<< ROLL THE DICE >>>>>')
while numbers > 0:
point = random.randrange(1,6)
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():
print('<<<<< GAME STARTS! >>>>>')
money = 10000
while money > 0:
print('You have:',money)
choices = ['Big','Small']
your_choice = input('Big or Small:')
your_bet = input('How much you wanna bet?:')
if your_choice in choices:
points = roll_dice()
total = sum(points)
youWin = your_choice==roll_result(total)
if youWin:
print('The points are:',points,'You Win!')
money = money+int(your_bet)
print('You gained',your_bet,',','You have',money,'now')
else:
print('The points are:',points,'You lose!')
money = money-int(your_bet)
print('You lost',your_bet,',','You have',money,'now')
else:
print('Invalid Words')
start_game()
start_game() |
-
实例
|