In [1]:
def compute_multi(end):
i = 1
total_n = 1
while i < end:
i = i + 1
total_n = total_n * i
return total_n
n = int(input('请输入第1个整数,以回车结束。'))
m = int(input('请输入第2个整数,以回车结束。'))
k = int(input('请输入第3个整数,以回车结束。'))
print('最终的和是:', compute_multi(m) + compute_multi(n) + compute_multi(k))
In [17]:
def compute(n):
i=0
total=0
while i<=n:
if i/2==0:
total=total+ 1/(2*i+1)
else:
total=total- 1/(2*i+1)
i=i+1
return total
print('当n等于1000时:',4*compute(1000))
print('当n=10000时:',4*compute(10000))
In [30]:
name=input('请输入你的名字:')
s=int(input('如果你是女性,请输入1,否则请输入2:'))
m = int(input('请输入你的出生月份:'))
n = int(input('请输入你的出生日期:'))
def your_sex(s):
if s==1:
sex='Miss'
else:
sex='Mr'
return sex
def constellation():
if m==1:
if n<21:
c='摩羯座'
else:
c='水瓶座'
if m==2:
if n<19:
c='水瓶座'
else:
c='双鱼座'
if m==3:
if n<21:
c='双鱼座'
else:
c='白羊座'
if m==4:
if n<20:
c='白羊座'
else:
c='金牛座'
if m==5:
if n<21:
c='金牛座'
else:
c='双子座'
if m==6:
if n<22:
c='双子座'
else:
c='巨蟹座'
if m==7:
if n<23:
c='巨蟹座'
else:
c='狮子座'
if m==8:
if n<23:
c='狮子座'
else:
c='处女座'
if m==9:
if n<23:
c='处女座'
else:
c='天秤座'
if m==10:
if n<24:
c='天秤座'
else:
c='天蝎座'
if m==11:
if n<23:
c='天蝎座'
else:
c='射手座'
if m==12:
if n<22:
c='射手座'
else:
c='摩羯座'
return c
your_sex(s)
constellation()
print('你好',your_sex(s),name,'你是',constellation())
In [21]:
some_string=(input('请输入一个单数形式的英语单词:'))
def plural():
if some_string.endswith('s') or some_string.endswith('sh') or some_string.endswith('ch') or some_string.endswith('x'):
print('加es')
elif some_string.endswith('y'):
print('变y为i再加es')
elif some_string.endswith('f') or some_string.endswith('fe'):
print('变f或fe为v再加es')
else:
print('直接加s')
plural()
In [32]:
def compute_total(m,n,tap):
i=m
total=0
while(i<n):
total=total+i
i=i+tap
return total
m = int(input('请输入开始整数,以回车结束。'))
n = int(input('请输入结束整数,以回车结束。'))
k = int(input('请输入间隔整数,以回车结束。'))
print('最终的和是:', compute_total(m,n,k))