欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-05-04 12:37:20
#游戏开始,首先玩家选择大小,选择完成后开始摇骰子(11<=总值<=18为大,3<=总值<=10为小) import random def roll_dice(numbers=3,points=None): # 创建3个筛子numbers,创建点数points print('<<<
#游戏开始,首先玩家选择大小,选择完成后开始摇骰子(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()