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

Posted liujinjing521

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python学习-55 小游戏- 猜大小相关的知识,希望对你有一定的参考价值。

#游戏开始,首先玩家选择大小,选择完成后开始摇骰子(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 小游戏- 猜大小的主要内容,如果未能解决你的问题,请参考以下文章

Python能做些什么及我的Python学习疑问

Pytho怎样自学?

pytho 的基本语法

入门学习python语言主要用途有哪些?

Python 大概 转

python学习之二