第五章 if语句

知识点

if:

if:
else:
if:
elif:
else:

作业

5.3

# alien_color = 'green'
# if alien_color == 'green':
#     print('You got 5 points')

# alien_color = 'blue'
# if alien_color == 'green':
#     print('You got 5 points')

alien_color = 'yellow'
if alien_color == 'green':
    print('You got 5 points')

5.4

alien_color = 'green'
if alien_color == 'green':
    print('You have got 5 points')
else:
    print('You have got 10 points')

# alien_color = 'yellow'
# if alien_color == 'green':
#     print('You have got 5 points')
# else:
#     print('You have got 10 points')

5.5

alien_color = 'red'
if alien_color == 'green':
    score = 5
elif alien_color == 'yellow':
    score = 10
else:
    score = 15
print('You have got '+ str(score)+ ' points.')

5.8-5.9

users1 = ['admin','sunshy','alan','dreamger','yibasoya']
users = []
if users:
    for user in users:
        if user == 'admin':
            print('"Hello ' + user.title()+',would you like to see a status report?"')
        else:
            print('"Hello '+ user.title()+',thank you for logging in again!"')
else:
    print('"We need to find some users!"')

5.10

current_users = ['admin','sunshy','alan','dreamger','yibasoya']
current_users = [c_u.lower() for c_u in current_users]  #将原有的用户名列表元素转为小写后存入新的列表
new_users = ['sunshy','Alan','candy','sufe','god']
for new_user in new_users:
    if new_user.lower() in current_users: #将新用户名的名称转为小写,对比原有用户名的小写,检查是否有重名
        print(new_user + ' is forbiden,please input another uers name.')
    else:
        print(new_user + ' is allowed,you can use this name.')