#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点!")
#5.4#2
alien_color = "yellow"
if alien_color == "green":
print("射杀绿色外星人获得5点!")
else:
print("射杀高级外星人获得10点!")
#5.5#3
if alien_color == "green":
print("射杀绿色外星人获得5点!")
elif alien_color =="yellow":
print("射杀黄色外星人获得10点!")
else:
print("射杀高级外星人获得15点!")
#5.6
age = 10
if age < 2:
print("婴儿")
elif age >= 2 and age < 4:
print("蹒跚学步")
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 = ["猕猴桃","苹果","西瓜"]
if "苹果" in favorite_fruits:
print("你真的好喜欢苹果呀!")
if "黄瓜" in favorite_fruits:
print("你真的好喜欢黄瓜呀!")
if "猕猴桃" in favorite_fruits:
print("你真的好喜欢猕猴桃呀!")
~~~~~~~~~~~~~~~~~~~~~~~~~~
False
True
True
True
True
True
False
False
True
True
False
恭喜你获得了5点!
射杀高级外星人获得10点!
射杀黄色外星人获得10点!
儿童
你真的好喜欢苹果呀!
你真的好喜欢猕猴桃呀!
#5.8
users = ["admin","Jack","波哥","波妞","大青"]
for user in users:
if user == "admin":
print("你好" + "管理员," + "您是否需要看一看状态报告?")
else:
print("你好" + user + "欢迎回来!")
#5.9
users = []
if not users:
print("没有用户啊")
for user in users:
if user == "admin":
print("你好" + "管理员," + "您是否需要看一看状态报告?")
else:
print("你好" + user + "欢迎回来!")
#5.10
current_users = ["boGe","波妞","大青","想飞","李白"]
new_users = ["Boge","啊啊","嗯嗯","啊哈","李白"]
for new_user in new_users:
#下面这种创建列表的方式为列表推导式(列表解析式)
if new_user.lower() in [current_user.lower() for current_user in current_users]:
print(new_user +"这个用户名已经存在,请重新起个名字")
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")
~~~~~~~~~~~~~~~~~~~~~~~
你好管理员,您是否需要看一看状态报告?
你好Jack欢迎回来!
你好波哥欢迎回来!
你好波妞欢迎回来!
你好大青欢迎回来!
没有用户啊
Boge这个用户名已经存在,请重新起个名字
啊啊未被使用
嗯嗯未被使用
啊哈未被使用
李白这个用户名已经存在,请重新起个名字
1st
2nd
3rd
4th
5th
6th
7th
8th
9th