#Ver.1:
alien_color = 'green'if alien_color == 'green':
print('You get 5 points')
elif alien_color == 'yellow':
print('You get 10 points')
elif alien_color == 'red':
print('You get 15 points')
#Ver.2:
alien_color = 'yellow'if alien_color == 'green':
print('You get 5 points')
elif alien_color == 'yellow':
print('You get 10 points')
elif alien_color == 'red':
print('You get 15 points')
#Ver.3:
alien_color = 'red'if alien_color == 'green':
print('You get 5 points')
elif alien_color == 'yellow':
print('You get 10 points')
elif alien_color == 'red':
print('You get 15 points')
5-6
age = 17if age < 2:
print("He's a baby")
elif age >= 2and age < 4:
print("He's learning to walk")
elif age >=4and age < 13:
print("He's a child")
elif age >= 13and age < 20:
print("He's a youth")
elif age >= 20and age <65:
print("He's a grown-up")
else:
print("He's a old man")
5-7
favorate_fruits = ['apple', 'orange', 'grape']
if'banana'in favorate_fruits:
print("Banana is my favorate fruit")
if'apple'in favorate_fruits:
print("Apple is my favorate fruit")
if'lemon'in favorate_fruits:
print("Lemon is my favorate fruit")
if'grape'in favorate_fruits:
print("Grape is my favorate fruit")
if'orange'in favorate_fruits:
print("Orange is my favorate fruit")
if'pear'in favorate_fruits:
print("Pear is my favorate fruit")
5-8
users = ['admin', 'Bob', 'Cathy', 'David', 'Eric']
for user in users:
if user == 'admin':
print("Hello admin, would you like to see a status report?")
else:
print("Hello " + user + ", thank you for logging in again")
5-9
users = ['admin', 'Bob', 'Cathy', 'David', 'Eric']
users.clear()
if users:
for user in users:
if user == 'admin':
print("Hello admin, would you like to see a status report?")
else:
print("Hello " + user + ", thank you for logging in again")
else:
print("We need to find some users")
5-10
current_users = ['Ann', 'Bob', 'Cathy', 'David', 'Eric']
new_users = ['Frank', 'Gary', 'Henry', 'bob', 'Eric' ]
for new_user in new_users:
name = new_user.lower().title()
if name in current_users:
print("The name:" + new_user + " has been used. Input again")
5-11
nums = range(1, 10)
for num in nums:
if num == 1:
print('1st')
elif num == 2:
print('2nd')
elif num == 3:
print('3rd')
else:
print(str(num) + 'st')