码迷,mamicode.com
首页 > 编程语言 > 详细

Python学习-55 小游戏- 猜大小

时间:2019-08-21 11:41:55      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:str   span   列表   points   bsp   学习   word   pen   imp   

#游戏开始,首先玩家选择大小,选择完成后开始摇骰子(11<=总值<=18为大,3<=总值<=10为小)

import random

def roll_dice(numbers=3,points=None):          # 创建3个筛子numbers,创建点数points
    print(<<<<roll the dice!>>>>)
    if points is None:
        points = []                             # 把点数放到一个空的列表里
    while numbers > 0:
        point = random.randrange(1,7)
        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 STRATS!>>>>)
    choices = [big,small]
    your_choice = input(big or small:)
    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!)
        else:
            print(The points are,points,YOU LOSE!)
    else:
        print(invalid words)
        start_game()
start_game()

 

Python学习-55 小游戏- 猜大小

标签:str   span   列表   points   bsp   学习   word   pen   imp   

原文地址:https://www.cnblogs.com/liujinjing521/p/11387419.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!