作业四

5-1 条件测试
things=['apple','dog','I','You','he','she','friends']
print('Is 'cat' in things? I guess no!')
'cat' in things #False,因为things列表中没有'cat'这项
print('Is 'dog' in things? I guess no!')
'dog' in things #True,因为'dog'在things中
print('Is 'DOG'.lower() in things? I guess no!')
'DOG'.lower() in things #True,因为'DOG'的小写为'dog'
print('Is "dog" in things? I guess yes!')
"dog" in things #True,不区分双引号和单引号

thingss=('apple','dog','I','You','he','she','friends')
print('Is thingss==things? I guess no!')
thingss==things #False,列表与元组不同
print("Are both 'dog' and 'cat' in things? I guess no!")
'dog' in things and 'cat' in things #False,因为虽然'dog'在列表中,但'cat'不在
print("Are both 'dog' or 'cat' in things? I guess yes!")
'dog' in things or 'cat' in things #False,因为虽然'car'不在列表中,但'dog'不在
pizza='hut'
print("If pizza=='hut'? I guess yes!")
print(pizza=='hut')#True,相等
print("If pizza=='hot'? I guess no!")
print(pizza=='hot')#False,不相等
print("If pizza=='hot' or pizza=='hut'? I guess yes!")
print(pizza=='hot' or pizza=='hut')#True,因为pizza=='hut'

5-3 外星人颜色1
alien_color=['green','yellow'.'red']
what_you_kill1='green'
what_you_kill2='red'
if what_you_kill1=='green':
 print("you get 5 points!")#若杀死的外星人为绿色,得5分
      #若无则没有输出
5-4(接5-3)
if what_you_kill1=='green':
 print("you get 5 points!")#若杀死的外星人为绿色,得5分
else:
 print("you get 10 points!")#若不是则得10分
5-5(接上)
if what_you_kill1=='green':
 print("you get 5 points!")#若杀死的外星人为绿色,得5分
elif what_you_kill1=='yellow':
 print("you get 10 points!")#若是黄色则得10分
elif what_you_kill1=='red':
 print("you get 15 points!")#红色15分~

总结:学习了条件判断以及if的用法,有几点需要注意的:
1、列表与元组不同,即使里面的元素一样。
2、if和else和elif后面都需要冒号。
3、可以用"if 列表名"判断列表是否为空。

你可能感兴趣的:(作业四)