#5.2
cars = [ 'bwm' , 'audi' , 'subaru' ]
a_str = 'BWM'
print( a_str == cars[0] )
print( a_str.lower() == cars[0] )
print( a_str.lower() in cars )
print( a_str.lower() not in cars )
#5.3-5.5
#5.3
alien_color = 'green'
if alien_color == 'green' :
print( "The player gets five points" )
if alien_color == 'red' :
print( "The color is red" )
#5.4
if alien_color == 'green':
print( "The player gets five points" )
else:
print( "The player gets ten points")
#5.5
if ( alien_color == 'green' ):
print( "The player gets five points" )
elif ( alien_color == 'red' ) :
print( "The player gets ten points" )
elif ( alien_color == 'yellow' ) :
print( "The player gets fifteen points" )
#5.6
age = input("please input your age\n")
age = int(age)
if age < 2 :
print( "婴儿")
elif age < 4 :
print( "你在蹒跚学步")
elif age < 13 :
print( "儿童")
elif age < 20 :
print( "青少年")
elif age < 65 :
print("成年人")
else:
print("90后老年人")
#5.7
favorite_fruits = ['apple' , 'banana' , 'orange' ]
fruits = [ 'apple' , 'pineapple' , 'banana' , 'pitaya', 'orange' ]
for fruit in fruits:
if fruit in favorite_fruits:
print( "you really like " + fruit )
else :
print( "you don't like " + fruit)
#5.8-5.9
names = ['admin' , 'a' , 'b' , 'c' ,'d' ]
for ele in names :
if ele == 'admin' :
print( "Hello admin, would you like to see a status report?" )
else :
print ("hello "+ele+", thank you for logging in again" )
if names.size() == 0 :
print( "We need to find some ueser!")
#5.10
current_users = ['a' ,'b' , 'c','d','e']
new_users = ['a' , 'adf' ,'B','fds' , 'lizhch']
for name in new_users :
flag = 1
for ele in current_users:
if name.lower() == ele.lower() :
print( "Please input another user name" )
flag = 0
if flag :
print( "It can be used" )
#5.11
nums = [ i for i in range(1,10) ]
for ele in nums :
if ele == 1 :
print( str(ele) + "st")
elif ele == 2 :
print( str(ele) + "nd" )
elif ele == 3 :
print( str(ele) + "rd" )
else :
print( str(ele) + "th" )