Python if-elif-else
alien_color = ['green','yellow','red']
for color in alien_color:
if color == 'green':
print 'alien_color_%s: player to obtain five !'%color
elif color == 'yellow':
print 'alien_color_%s: player to obtain ten !' % color
else:
print 'alien_color_%s: player to obtain ten-five !' % color
try:
age = input('please value a integer:') #####input输入的是整数,raw_input输入的是字符串
if int(age) < 2:
print 'he is a baby!'
elif int(age) >= 2 and int(age) < 4:
print 'he is going!'
elif int(age)>= 4 and int(age) < 13:
print 'he is a teenager!'
elif int(age) >= 13 and int(age) < 65:
print 'he is a Middle-aged people!'
else:
print 'he is a old people!'
except:
print 'please value a integer!'
登录打招呼
user_name = ['admin', 'jack', 'bob', 'tom', 'mary']
for value in user_name:
value = raw_input('please value a user name:')
if value == 'admin':
print 'hello %s, would you like to see a status report?'% value
break
elif value not in user_name:
print 'error value'
break
else:
print 'hello %s, thank you for logging in again' % value
break
lists = [1,2,3,4,5,6,7,8,9]
for i in lists:
if i == 1:
print str(i) + 'st'
elif i == 2:
print str(i) + 'nd'
elif i == 3:
print str(i) + 'rd'
else:
print str(i) + 'th'
窈窕包包,君子好逑