练习1
In [1]:
def compute_pro(end):
i=1
pro_n = 1
while i<end:
i=i+1
pro_n = pro_n * i
return pro_n
m=int(input('请输入一个整数,以回车结束'))
n=int(input('请输入一个整数,以回车结束'))
k=int(input('请输入一个整数,以回车结束'))
print('最终的和是',compute_pro(m)+compute_pro(n)+compute_pro(k))
练习2
In [2]:
def compute_sum(end):
i=1
total_k=0
n=0
m=0
while i<end:
n= 1/(2*i-1)
m= 1/(2*i+1)
total_k=total_k+n-m
i=i+2
return total_k
k=int(input('plz'))
print('最终的和是',4*compute_sum(k))
In [3]:
def compute_sum(end):
i=1
total_k=0
n=0
m=0
while i<end:
n= 1/(2*i-1)
m= 1/(2*i+1)
total_k=total_k+n-m
i=i+2
return total_k
k=int(input('plz'))
print('最终的和是',4*compute_sum(k))
练习3 (1
In [4]:
def n(date):
if 1.19<date<2.19:
return('你是水瓶座')
if 2.18<date<3.21:
return('你是双鱼座')
if 3.20<date<4.20:
return('你是白羊座')
if 4.19<date<5.21:
return('你是金牛座')
if 5.20<date<6.22:
return('你是双子座')
if 6.21<date<7.23:
return('你是巨蟹座')
if 7.22<date<8.23:
return('你是狮子座')
if 3.22<date<9.23:
return('你是处女座')
if 9.22<date<10.24:
return('你是天枰座')
if 10.23<date<11.23:
return('你是天蝎座')
if 11.22<date<12.22:
return('你是射手座')
if date>12.21 or date<1.20:
return('你是摩羯座')
date=float(input('请输入你的生日'))
print(n(date))
练习3 (4
In [5]:
def n(word):
if word.endswith('s'):
return('加es')
if word.endswith('x'):
return('加es')
else:
return('加s')
word=str(input('请输入'))
print(n(word))
挑战性练习
In [6]:
def compute_sum(end):
i=m
total=i
end=n
if i<end:
while i<end:
i=i+k
total=total+i
return total
elif i>=end:
while i> end:
i=i-k
total=total+i
return total
m=int(input('请输入'))
n=int(input('请输入,m与n不等'))
k=int(input('请输入'))
print(compute_sum(n))