In [1]:
#练习 1:写程序,可由键盘读入用户姓名例如Mr. right,让用户输入出生的月份与日期,判断用户星座,假设用户是金牛座,
#则输出,Mr. right,你是非常有性格的金牛座!。
n=str(input('plz input ur name '))
m=int(input('input ur birth month '))
d=int(input('input ur birth day '))
if (m>=3 and d>21) or (m<=4 and d<19):
        print (n,'你是白羊座')
elif (m>=4 and d>20) or (m<=5 and d<20):
        print (n,'你是金牛座')
elif (m>=5 and d>21) or (m<=6 and d<21):
        print (n,'你是双子座')
elif (m>=6 and d>22) or (m<=7 and d<22):
        print (n,'你是巨蟹座')
elif (m>=7 and d>23) or (m<=8 and d<22):
        print (n,'你是狮子座')
elif (m>=8 and d>23) or (m<=9 and d<22):
        print (n,'你是处女座')
elif (m>=9 and d>23) or (m<=10 and d<23):
        print (n,'你是天秤座')
elif (m>=10 and d>24) or (m<=11 and d<23):
        print (n,'你是天蝎座')
elif (m>=11 and d>23) or (m<=12 and d<21):
        print (n,'你是射手座')
elif (m>=12 and d>22) or (m<=1 and d<19):
        print (n,'你是摩羯座')
elif (m>=1 and d>20) or (m<=2 and d<18):
        print (n,'你是水瓶座')
elif (m>=2 and d>19) or (m<=3 and d<20):
        print (n,'你是双鱼座')


plz input ur name jessica
input ur birth month 8
input ur birth day 15
jessica 你是狮子座

In [2]:
#练习 2:写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,
#如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。
m=int(input('plz input m: '))
n=int(input('plz input n: '))

a=str(input('plz  input one of +  * % ops: '))
if a== '+':
    print (m+n)
elif a=='*':
    print (m*n)
elif a=='%':
    print (m%n)
else:
    print(int(m/n))


plz input m: 5
plz input n: 9
plz  input one of +  * % ops: +
14

In [3]:
#练习 3:写程序,能够根据北京雾霾PM2.5数值给出对应的防护建议。如当PM2.5数值大于500,则应该打开空气净化器,戴防雾霾口罩等。
n=int(input('plz input pm2.5: '))
if n>500:
    print ('应该打开空气净化器,戴防雾霾口罩')
else:
    print('good weather,good day!')


plz input pm2.5: 567
应该打开空气净化器,戴防雾霾口罩

In [4]:
#练习 4:英文单词单数转复数,要求输入一个英文动词(单数形式),能够得到其复数形式,
#或给出单数转复数形式的建议(提示,some_string.endswith(some_letter)函数可以判断某字符串结尾字符,
word=str(input('plz input a word'))
if(word.endswith('ch') or word.endswith('sh') or word.endswith('o') or word.endswith('x') or word.endswith('s')  ):
    print(word,'es',sep='')
else:
    print(word,'s',sep='')


plz input a wordtomato
tomatoes

In [10]:
max_num=int(input('plz input a num : '))
sec_num=int(input('plz input a num : '))
if sec_num > max_num:
    sec_num.max_num=max_num,sec_num
    
number=None
while number != 10086:
    number=int(input('plz input a num end with 10086 : '))
    if number > max_num:
        sec_num=max_num
        max_num=number
    elif number > sec_num:
        sec_num=number
    else:
        pass
    
print ('the second num is : ',sec_num)


plz input a num : 46
plz input a num : 46
plz input a num end with 10086 : 456
plz input a num end with 10086 : 235
plz input a num end with 10086 : 678
plz input a num end with 10086 : 46
plz input a num end with 10086 : 9864
plz input a num end with 10086 : 10086
the second num is :  9864

In [ ]: