# alien_color_1_1.py
alien_color = 'green'
if alien_color == 'green' :
print("You've got five points.")
Output
You’ve got five points.
# alien_color_1_2.py
alien_color = 'yellow'
if alien_color == 'green' :
print("You've got five points.")
Output
None
# alien_color_2_1.py
alien_color = 'green'
if alien_color == 'green':
print("You've got five points.")
else:
print("You've got ten points.")
Output
You’ve got five points.
# alien_color_2_2.py
alien_color = 'yellow'
if alien_color == 'green':
print("You've got five points.")
else:
print("You've got ten points.")
Output
You’ve got ten points.
# alien_color_2_1.py
alien_color = 'red'
if alien_color == 'green':
print("You've got five points.")
elif alien_color == 'yellow':
print("You've got ten points.")
else:
print("You've got fifteen points.")
Output
None
# ages.py
age = 20
if age < 2 :
print("He's a baby.")
elif age < 4 :
print("He's learning to walk.")
elif age < 13 :
print("He's a child.")
elif age < 20 :
print("He's a teenager.")
elif age < 65 :
print("He's a adult.")
else:
print("He's a old man.")
Output
None
# favorite_fruits.py
favorite_fruits = ['apple','banana','peach','strawberry','pear']
if 'apple' in favorite_fruits:
print("You really like apple!")
if 'lemon' in favorite_fruits:
print("You really like lemon!")
if 'strawberry' in favorite_fruits:
print("You really like strawberry!")
if 'plum' in favorite_fruits:
print("You really like plum!")
if 'pear' in favorite_fruits:
print("You really like pear!")
Output
You really like apple!
You really like strawberry!
You really like pear!
# special_hello.py
administrators = ['admin','user1','user2','user3','user4']
for admin in administrators:
if admin == 'admin':
print("Hello admin, would you like to see a status report?")
else:
print("Hello "+ admin + ", thank you for logging in again.")
Output
Hello admin, would you like to see a status report?
Hello user1, thank you for logging in again.
Hello user2, thank you for logging in again.
Hello user3, thank you for logging in again.
Hello user4, thank you for logging in again.
# no_user.py
administrators = []
if not administrators:
print("We need to find some users!")
Output
We need to find some users!
# check_user.py
current_users = ['admin','user1','user2','user3','user4']
new_users = ['admin','user5','user6','user2','user7']
for new_user in new_users:
if new_user.lower() in current_users or new_user.upper() in current_users:
print(new_user+" is used, choose another name.")
else:
print(new_user + " is available.")
Output
admin is used, choose another name.
user5 is available.
user6 is available.
user2 is used, choose another name.
user7 is available.
# list.py
lists = list(range(1,10))
for i in lists:
if i == 1:
print("1st")
elif i == 2:
print("2nd")
elif i == 3:
print("3rd")
else:
print(str(i)+"th")
Output
1st
2nd
3rd
4th
5th
6th
7th
8th
9th