In [10]:
#练习1#
name = input('请输入您的姓名,以回车结束')
date = float(input('请输入您的出生日期,以回车结束。如1月1日写为 1.1'))
if 4.2 <= date <= 5.2:
print(name, '您是非常有个性的金牛座!')
In [1]:
#练习2#
m = int(input('请输入一个整数,回车结束。'))
n = int(input('请输入一个整数,回车结束。'))
command = input('请输入要选择的算法(求和、乘积、余数、整除),回车结束。')
if command == '求和':
print(m + n)
elif command == '乘积':
print(m * n)
elif command == '余数':
print(m % n)
else:
print(m // n)
In [2]:
#练习3#
m = int(input('请输入北京的PM2.5值,回车结束。'))
if m > 500 :
print('请打开空气净化器')
elif 200 <= m <=500:
print('请减少出门频率')
else :
print('请佩戴防霾口罩')
In [9]:
#练习4#
some_string = input('请输入一个英文名词,以回车结束。')
if some_string.endswith('x' or 'ch' or 'sh'):
print(some_string,'es',sep = '')
elif some_string == 'tomato' or 'potato' or 'hero' or 'negro':
print(some_string,'es',sep = '')
elif some_string.endswith('y') and (not some_string.endswith('ay' or 'ey' or 'iy' or 'oy' or 'uy')):
print(some_string[0:-1],'ies',sep = '')
else :
print(some_string,'s',sep = '')
In [13]:
#挑战练习#
m = int(input('请输入要输入的整数个数,回车结束。'))
max1_number = int(input('请输入一个整数,回车结束'))
max2_number = 0
i=1
while i <m:
i = i+1
n= int(input('请输入一个整数,回车结束'))
if n >= max1_number:
max2_number = max1_number
max1_number = n
elif n < max1_number and n> max2_number:
max2_number = n
print('次大值是:', max2_number, sep = '')
In [16]:
#尝试练习#
print(10,20, sep = '\n\n')
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [11]:
a = "apple"
print (a[0:-1])
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: