In [1]:
#练习1
name=input('What is your name? ')
x=int(input('Enter the date of your birthday'))
if x>=420 and x<=520  :
    print('Mr. right,你是非常有性格的金牛座!')
else:
    print('Mr. right,你不是金牛座。')


What is your name? Mr.right
Enter the date of your birthday425
Mr. right,你是非常有性格的金牛座!

In [2]:
#练习2
m = int(input('Enter an integer:'))
n = int(input('Enter another integer,and it is not zero'))
operation=input('What do you want to do with the two numbers?')
if operation.endswith('plus'):
    print('The sum is: ',m+n)
else:
    print('The result is: ',n/m)


Enter an integer:5
Enter another integer,and it is not zero2
What do you want to do with the two numbers?plus
The sum is:  7

In [3]:
#练习3
num = int(input('Enter the PM2.5 value: '))
if num>500:
    print('应该打开空气净化器,戴防雾霾口罩')
else :
    print('It is no problem')


Enter the PM2.5 value: 520
应该打开空气净化器,戴防雾霾口罩

In [5]:
#练习4
word=input('Enter a noun: ')
if word.endswith('y'):  
    print('变y为i加es') 
elif word[-1] in 'sx' or word[-2:] in ['sh','ch']:  
    print('加es')  
else:  
    print('加s')


Enter a noun: fly
变y为i加es

In [6]:
#尝试性练习
print(' ',sep = '  ')


 

In [8]:
#挑战性练习
m = int(input('请输入要输入的整数个数,回车结束。'))
a = []
i = 0
while i <m:
    a.append(int(input('Enter an integer: ')))
    i = i + 1
print('',a)
b=a[:]
b.sort()
print('',b[3])


请输入要输入的整数个数,回车结束。5
Enter an integer: 2
Enter an integer: 9
Enter an integer: 3
Enter an integer: 4
Enter an integer: 8
 [2, 9, 3, 4, 8]
 8

In [ ]:


In [ ]:


In [ ]: