In [1]:
#练习1#
def compute_multi(end):
    i = 0
    total = 1
    
    while i < end:
        i = i+1
        total = total*i
    return total

m = int(input('请输入第一个整数,以回车结束'))
n = int(input('请输入第二个整数,以回车结束'))
k = int(input('请输入第三个整数,以回车结束'))

print('最终的结果是:', compute_multi(m)+compute_multi(n)+compute_multi(k), sep = '')


请输入第一个整数,以回车结束2
请输入第二个整数,以回车结束5
请输入第三个整数,以回车结束4
最终的结果是:146

In [2]:
#练习2#
def compute_1(n):
    i = 0
    total = 0
    
    while i < n:
        i = i+1
        m= 1/(2*i-1)*((-1)**(i+1))
        total = total+m
    return total

print(compute_1(1000)*4)
print(compute_1(100000)*4)


3.140592653839794
3.1415826535897198

In [3]:
#练习3-1#
def compute_1(n,m):
    if 4.2 <= n <= 5.2:
        k = m+',您是非常有个性的金牛座!'
        return k

name = input('请输入您的姓名,以回车结束')
date = float(input('请输入您的出生日期,以回车结束。如1月1日写为 1.1'))

print(compute_1(date,name))


请输入您的姓名,以回车结束lowkey
请输入您的出生日期,以回车结束。如1月1日写为 1.14.3
lowkey,您是非常有个性的金牛座!

In [4]:
#练习3-2#
def compute_1(n):
    if n.endswith('x' or 'ch' or 'sh'):
        k = n+'es'  
    elif n == 'tomato' or 'potato' or 'hero' or 'negro':
        k = n+'es'
    elif n.endswith('y') and (not some_string.endswith('ay' or 'ey' or 'iy' or 'oy' or 'uy')):
        k = n[0:-1]+'ies'
    else :
        k = n+'s'
    return k

n = input('请输入一个英文名词,以回车结束。')
print(compute_1(n))


请输入一个英文名词,以回车结束。fox
foxes

In [5]:
#挑战练习#
def compute_1(m,n,k):
    number = (n-m)/k+1
    total = (m+n)*number/2
    return total
m = int(input('请输入开始的整数,以回车结束'))
n = int(input('请输入结束的整数,以回车结束'))
k = int(input('请输入间距(整数),以回车结束'))
print(compute_1(m,n,k))


请输入开始的整数,以回车结束2
请输入结束的整数,以回车结束20
请输入间距(整数),以回车结束2
110.0

In [ ]: