10月 132020
 
import random #引入random库

#在指定起始值范围内随机取值
point1 = random.randrange(1,7)
point2 = random.randrange(1,7)
point3 = random.randrange(1,7)

#
def points():
    return str(point1), str(point2), str(point3) #返回三个变量值

#累加计算三个随机数并判断大小
def calc():
    values = point1 + point2 + point3 #累加计算
    if 11 <= values <= 18:
        return 'Big'
    elif 3 <= values <= 10:
        return 'Small'

#执行
print('>>> START <<<')
choose = input('Input Big or Small: ') #用户输入大小赋值变量
abc = points() #调用函数返回三个随机数并赋值变量
print('The points are {}'.format(abc)) #使用格式化字符串打印变量值

#定义状态列表,并判断状态
status = ['You are win!', 'You are lose!']
if choose == calc(): #判断,用户输入与函数计算返回值比较运算,一致返回成功
    print(status[-2])
else: #反之,不一致返回失败
    print(status[-1])
PS D:\Python> & C:/Users/harveymei/AppData/Local/Programs/Python/Python39/python.exe d:/Python/hello.py
>>> START <<<
Input Big or Small: Big
The points are ('5', '6', '3')
You are win!
PS D:\Python>

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据