python编写摇骰子游戏_python摇骰子猜大小的小游戏

#小游戏,摇筛子押大小的小游戏

玩家初始有1000块钱,可以压大压小作为赌注

import random

#定义摇筛子的函数:

def roll_dice(number = 3,points = None):

print ('<<<<< Roll The Dice >>>>>')

if points is None:

points = []

while number > 0:

point = random.randrange(1,7)

points.append(point)

number = number - 1

return points

#将点数转换为大小的函数:

def roll_result(total):

isBig = 11 <= total < 18

isSmall = 3 <= total < 10

if isBig:

return 'isBig'

elif isSmall:

return 'isSmall'

#开始游戏的函数;

def start_game():

you_money = 1000

while you_money > 0:

print ('<<<<< GAME START >>>>>')

choices = ['isBig','isSmall']

your_choices = input('isBig or isSmall:')

if your_choices in choices:

you_bet = int(input('How nuch you wana bet? :'))

points = roll_dice()

total = sum(points)

youWin = your_choices == roll_result(total)

if youWin:

you_money = you_money + you_bet

print('The points are', points, 'You win !')

print('You gained {},you have {} now'.format((you_bet,you_money)))

else:

you_money = you_money - you_bet

print('The points are', points, 'You lose !')

print('You lost {},you have {} now'.format(you_bet,you_money))

else:

print('Invalid Words')

else:

print ('GAME IS OVER!')

start_game()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值