In [1]:
n = int(input('请输入第1个整数,以回车结束。'))
i = 0
total_n = 1
while i < n:
i = i + 1
total_n = total_n * i
m = int(input('请输入第2个整数,以回车结束。'))
i = 0
total_m = 1
while i < m:
i = i + 1
total_m = total_m * i
k = int(input('请输入第3个整数,以回车结束。'))
i = 0
total_k = 1
while i < k:
i = i + 1
total_k = total_k *i
print('m!+n!+k!:', total_n + total_m + total_k)
In [4]:
def compute_sum(end):
i=1
m=1
total_n=1
while i<end:
m+=2
total_n+=1/m*pow(-1,i)
i+=1
return total_n
a=1000
b=100000
print('最终的和是:', 4*compute_sum(a), 4*compute_sum(b))
In [18]:
def birthday(date):
if 1.19<date<2.19:
return('你是水瓶座')
elif 2.18<date<3.21:
return('你是双鱼座')
elif 3.20<date<4.20:
return('你是白羊座')
elif 4.19<date<5.21:
return('你是金牛座')
elif 5.20<date<6.22:
return('你是双子座')
elif 6.21<date<7.23:
return('你是巨蟹座')
elif 7.22<date<8.23:
return('你是狮子座')
elif 3.22<date<9.23:
return('你是处女座')
elif 9.22<date<10.24:
return('你是天枰座')
elif 10.23<date<11.23:
return('你是天蝎座')
elif 11.22<date<12.22:
return('你是射手座')
else:
return('你是摩羯座')
date=float(input('请输入你的生日'))
print(birthday(date))
In [ ]:
def switch_word(noun):
if noun.endwith('x','ch'):
return('加 es')
if noun.endwith('y'):
return('变y为i,加es')
else:
return('加 s')
word=input('请输入一个单数名词: ')
print('该单词的复数形式为: ',switch_word(word))
In [6]:
def compute_sum(x,y,z):
total_sum=0
while x<=y:
x+=z
total_sum+=x
return total_sum
m=int(input('请输入一个整数m: '))
n=int(input('请输入一个大于m的整数n: '))
k=int(input('请输入间隔k: '))
print('最终的和是:', compute_sum(m,n,k))