#5.2
print("car" == "car ") #False
print("car" == "car") #True
print("car" == "Car".lower()) #True
print((10-3) == 7) #True
print((10-3) != 8) #True
print(10 > 3) #True
print(10 >= 13) #False
print(10 >3 and 3 >3) #False
print(10 >3 or 3 >3) #True
lst = ['a',3,'哈哈']
lst1 = 3
print(lst1 in lst) #True
print('哈哈' not in lst) #False
#5.3#1
alien_color = "green"
if alien_color == "green":
print("恭喜你獲得了5點(diǎn)懦尝!")
#5.4#2
alien_color = "yellow"
if alien_color == "green":
print("射殺綠色外星人獲得5點(diǎn)!")
else:
print("射殺高級(jí)外星人獲得10點(diǎn)拐格!")
#5.5#3
if alien_color == "green":
print("射殺綠色外星人獲得5點(diǎn)赞别!")
elif alien_color =="yellow":
print("射殺黃色外星人獲得10點(diǎn)破花!")
else:
print("射殺高級(jí)外星人獲得15點(diǎn)紊撕!")
#5.6
age = 10
if age < 2:
print("嬰兒")
elif age >= 2 and age < 4:
print("蹣跚學(xué)步")
elif age >= 4 and age < 13:
print("兒童")
elif age >= 13 and age < 20:
print("青少年")
elif age >= 20 and age < 65:
print("成年人")
else:
print("老年人")
#5.7
favorite_fruits = ["獼猴桃","蘋(píng)果","西瓜"]
if "蘋(píng)果" in favorite_fruits:
print("你真的好喜歡蘋(píng)果呀楼眷!")
if "黃瓜" in favorite_fruits:
print("你真的好喜歡黃瓜呀十性!")
if "獼猴桃" in favorite_fruits:
print("你真的好喜歡獼猴桃呀!")
~~~~~~~~~~~~~~~~~~~~~~~~~~
False
True
True
True
True
True
False
False
True
True
False
恭喜你獲得了5點(diǎn)葵诈!
射殺高級(jí)外星人獲得10點(diǎn)!
射殺黃色外星人獲得10點(diǎn)祟同!
兒童
你真的好喜歡蘋(píng)果呀作喘!
你真的好喜歡獼猴桃呀!
#5.8
users = ["admin","Jack","波哥","波妞","大青"]
for user in users:
if user == "admin":
print("你好" + "管理員晕城," + "您是否需要看一看狀態(tài)報(bào)告泞坦?")
else:
print("你好" + user + "歡迎回來(lái)!")
#5.9
users = []
if not users:
print("沒(méi)有用戶(hù)啊")
for user in users:
if user == "admin":
print("你好" + "管理員砖顷," + "您是否需要看一看狀態(tài)報(bào)告贰锁?")
else:
print("你好" + user + "歡迎回來(lái)!")
#5.10
current_users = ["boGe","波妞","大青","想飛","李白"]
new_users = ["Boge","啊啊","嗯嗯","啊哈","李白"]
for new_user in new_users:
#下面這種創(chuàng)建列表的方式為列表推導(dǎo)式(列表解析式)
if new_user.lower() in [current_user.lower() for current_user in current_users]:
print(new_user +"這個(gè)用戶(hù)名已經(jīng)存在滤蝠,請(qǐng)重新起個(gè)名字")
else:
print(new_user + "未被使用")
#5.11
nums = [i for i in 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) + "th")
~~~~~~~~~~~~~~~~~~~~~~~
你好管理員豌熄,您是否需要看一看狀態(tài)報(bào)告?
你好Jack歡迎回來(lái)物咳!
你好波哥歡迎回來(lái)锣险!
你好波妞歡迎回來(lái)!
你好大青歡迎回來(lái)览闰!
沒(méi)有用戶(hù)啊
Boge這個(gè)用戶(hù)名已經(jīng)存在芯肤,請(qǐng)重新起個(gè)名字
啊啊未被使用
嗯嗯未被使用
啊哈未被使用
李白這個(gè)用戶(hù)名已經(jīng)存在,請(qǐng)重新起個(gè)名字
1st
2nd
3rd
4th
5th
6th
7th
8th
9th