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>

10 月 132020
 
def text_creation():
    path = 'C:/Users/harveymei/Desktop/'
    for name in range(1,11):
        with open(path + str(name) + '.txt', 'w') as text: #文件操作
            text.write(str(name)) #写入内容
            text.close()
            print('Done')
text_creation()
def invest(amount, rate, time):
    print('principal amount: {}'.format(amount)) #字符串格式化填充
    for t in range(1, time + 1):
        amount = amount * (1 + rate)
        print('year {}: ${}'.format(t, amount))
invest(100, .05, 8)
invest(2000, .025, 5)
def even_print():
    for i in range(1,101):
        if i % 2 == 0:
            print(i)
even_print()