首页 > 编程语言 > 详细

python摇骰子猜大小的小游戏

时间:2016-10-28 19:40:28      阅读:504      评论:0      收藏:0      [点我收藏+]
#小游戏,摇筛子押大小的小游戏
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():
    print (‘<<<<< GAME START >>>>>‘)
    choices = [‘isBig‘,‘isSmall‘]
    your_choices = input(‘isBig or isSmall:‘)
    if your_choices in choices:
        points = roll_dice()
        total = sum(points)
        youWin = your_choices == roll_result(total)
        if youWin:
            print(‘The points are‘, points, ‘You win !‘)
        else:
            print(‘The points are‘, points, ‘You lose !‘)
    else:
        print(‘Invalid Words‘)
start_game()

  

python摇骰子猜大小的小游戏

原文:http://www.cnblogs.com/pythonal/p/6008834.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!