#5-7
favorite_fruits = ['apple', 'banana', 'pinanapple', 'microsoft', 'orange']
if 'apple' in favorite_fruits:
print('You really like apple!')
if 'Banana' in favorite_fruits:
print("You really like bannaa!")
if 'google' in favorite_fruits:
print('You really like apple!')
if 'steam' in favorite_fruits:
print("You really like bannaa!")
if 'orange' in favorite_fruits:
print('You really like apple!')
print("\n")
#5-8
names = ['thinker', 'bai', 'bus driver', 'admin', 'ryoma']
for name in names:
if name == 'admin':
print("Hello admin, would you like to see a status report?")
else:
print("Hello " + name.title() + ", thank you for logging in again.")
print("\n")
#5-9
names.clear()
if len(names) == 0:
print("We need to find some users!")
print("\n")
#5-10
current_users = ['thinker', 'bai', 'bus driver', 'admin', 'ryoma']
new_users = ['good man', 'Bai', 'adMin', 'bad driver', 'phd']
for new_user in new_users:
if new_user.lower() in current_users:
print(new_user + " is used")
else:
print("OK to use " + new_user)
print("\n")
#5-11
numbers = range(1, 10)
output = ""
for number in numbers:
if number == 1:
output += '1st '
elif number == 2:
output += '2nd '
elif number == 3:
output += '3rd '
else :
output += str(number) + 'th '
print(output)
输出结果如下:
You really like apple!
You really like apple!
Hello Thinker, thank you for logging in again.
Hello Bai, thank you for logging in again.
Hello Bus Driver, thank you for logging in again.
Hello admin, would you like to see a status report?
Hello Ryoma, thank you for logging in again.
We need to find some users!
OK to use good man
Bai is used
adMin is used
OK to use bad driver
OK to use phd
1st 2nd 3rd 4th 5th 6th 7th 8th 9th