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 = '')
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)
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))
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))
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))
In [ ]: