In [6]:
## 求m!+n!+k!
def compute_ji(end):
i = 0
ji = 1
while i < end:
i = i + 1
ji = ji * i
return ji
n = int(input('请输入第1个整数,以回车结束。'))
m = int(input('请输入第2个整数,以回车结束。'))
k = int(input('请输入第3个整数,以回车结束。'))
print('最终的和是:', compute_ji(m) + compute_ji(n) + compute_ji(k))
In [4]:
def compute_sum(end):
i = 1
j = 3
sum1 = 1
sum2 = 1/3
while i <= end:
i = i+4
sum1 = sum1 + 1/i
j = j+4
sum2 = sum2 + 1/j
return sum1-sum2
print('n=1000时 4倍该函数和为:',4*compute_sum(1000))
print('n=100000时 4倍该函数和为:',4*compute_sum(100000))
In [12]:
#task3 1
def Constellation(d):
if d>=3.21 and d<=4.19:
print(name,'你是白羊座')
elif d>=4.20 and d<=5.20:
print(name,'你是金牛座')
elif d>=5.21 and d<=6.21:
print(name,'你是双子座')
elif d>=6.22 and d<=7.22:
print(name,'你是巨蟹座')
elif d>=7.23 and d<=8.22:
print(name,'你是狮子座')
elif d>=8.23 and d<=9.22:
print(name,'你是处女座')
elif d>=9.23 and d<=10.23:
print(name,'你是天秤座')
elif d>=10.24 and d<=11.22:
print(name,'你是天蝎座')
elif d>=11.23 and d<=12.21:
print(name,'你是射手座')
elif d>=12.22 or d<=1.19:
print(name,'你是摩羯座')
name=input('请输入你的姓名,以回车结束。')
date=float(input('请输入你的出生日期,以回车结束。'))
Constellation(date)
In [13]:
#task3 4
def word(m):
if m.endswith('s') or m.endswith('x') or m.endswith('z') or m.endswith('ch') or m.endswith('sh'):
print('复数为:',m,'es')
elif m.endswith('y'):
print('复数为:把y改为i再加es')
elif m.endswith('f') or m.endswith('fe'):
print('复数为:把f或fe改为v再加es')
else:
print('复数为:',m,'s')
m = str(input('请输入要输入的英文单词,回车结束。'))
word(m)
In [17]:
def total(m,n,k):
i=m
total=0
while i<=n:
total=total+i
i=i+k
return(total)
m = int(input('请输入第1个整数,以回车结束。'))
n = int(input('请输入第2个整数,以回车结束。'))
k = int(input('请输入第3个整数,以回车结束。'))
print('和为:',total(m,n,k))