In [2]:
def compute_sum(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_sum(m) + compute_sum(n) + compute_sum(k))
In [10]:
def compute_sum(end):
i = 1
total_n = 1
while i < end:
i = ((-1)**i)*(2 * i + 1)
total_n = total_n - 1/i
return total_n
m = 1000
print('最终的和是:', compute_sum(m)*4)
n = 100000
print('最终的和是:', compute_sum(n)*4)
In [16]:
name = input('请输入你的姓名,以回车结束。')
print('你好', name)
def cons_day(day):
if 3.21<= day and day<= 4.19:
print('你是白羊座')
elif 4.20<=day and day<=5.20:
print ('你是金牛座')
elif 5.21<=day and day<=6.21:
print ('你是双子座')
elif 6.22<=day and day<=7.22:
print ('你是巨蟹座')
elif 7.23<=day and day<=8.22:
print ('你是狮子座')
elif 8.23<=day and day<=9.22:
print ('你是处女座')
elif 9.23<=day and day<=10.23:
print ('你是天秤座')
elif 10.24<=day and day<=11.22:
print ('你是天蝎座')
elif 11.23<=day and day<=12.21:
print ('你是射手座')
elif 1.20<=day and day<=2.18:
print ('你是水瓶座')
elif 2.19<=day and day<=3.20:
print ('你是双鱼座')
elif 12.22<=day and day<=12.30 or 1.01<=day and day <=1.19
print ('你是摩羯座')
day = input('请输入你的生日x.x,以回车结束')
cons_day(day)
In [1]:
def compute_sum(end):
i = m
total_n = 0
while i < n:
i = i + k
total_n = total_n + i
return total_n
n = int(input('请输入第1个整数,以回车结束。'))
m = int(input('请输入第2个整数,以回车结束。'))
k = int(input('请输入第3个整数,以回车结束。'))
print('最终的和是:', compute_sum(n))
In [2]:
def compute(some_string):
if some_string=='photo'or some_string=='piano':
print('在词尾加s')
elif some_string.endswith('s')or some_string.endswith('x')or some_string.endswith('o')or some_string.endswith('sh')or some_string.endswith('ch'):
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')
some_string=input('请输入一个单数单词')
compute(some_string)
In [18]:
def birth(birth_month,birth_day):
if birth_month==12:
if birth_day>21:
print('您是摩羯座')
else:
print('你是射手座')
if birth_month==11:
if bitrh_day>22:
print('你是射手座')
else:
print('你是天蝎座')
if birth_month==10:
if birth_day>23:
print('您是天蝎座')
else:
print('您是天秤座')
if birth_month==9:
if birth_day>22:
print('您是天秤座')
else:
print('您是处女座')
if birth_month==8:
if bitrh_day>22:
print('您是处女座')
else:
print('您是狮子座')
if birth_month==7:
if birth_day>22:
print('您是狮子座')
else:
print('您是巨蟹座')
if birth_month==6:
if birth_day>22:
print('你是巨蟹座')
else:
print('您是双子座')
if birth_month==5:
if birth_day>20:
print('您是双子座')
else:
print('您是金牛座')
if birth_month==4:
if birth_day>19:
print('您是金牛座')
else:
print('您是白羊座')
if birth_month==3:
if birth_day>20:
print('您是白羊座')
else:
print('您是双鱼座')
if birth_month==2:
if birth_day>18:
print('您是双鱼座')
else:
print('您是水瓶座')
if birth_month==1:
if birth_day>19:
print('您是水瓶座')
else:
print('您是摩羯座')
name=input('请输入您的姓名,以回车结束')
print('Hello',name)
birth_month=int(input('请输入您的出生月份,以回车结束'))
birth_day=int(input('请输入您的出生日期,以回车结束'))
birth(birth_month,birth_day)
In [ ]:
In [ ]: