#5.1
major = 'Software Engineering'
print("Is major =='Software Engineering'? I predict True.")print(major=='Software Engineering')print("Is major =='Software Engineering'? I predict False.")print(major=='Computer Science')#5.2
print("--------------------------------------")
string_1='abc'string_2='abc'string_3='abcd'
print("Is string_1==string_2?")print(string_1==string_2)print("Is string_2==string_3?")print(string_2==string_3)print("--------------------------------------")print("Is string_1 == string_1.lower()?")print(string_1==string_1.lower())print("--------------------------------------")print("这个部分实在过于简单和麻烦,略过!")print("--------------------------------------")print(True andFalse)print(True andTrue)print(False andFalse)print(True orFalse)print(True orTrue)print(False orFalse)print("--------------------------------------")
mobileInc= ['apple','xiaomi','huawei','oppo','vivo']print('apple' inmobileInc)print('coolpad' inmobileInc)print('nokia' not inmobileInc)#5.3
alien_color = 'green'
if alien_color == 'green':print("Great!You got 5 point!")
alien_color= 'red'
if alien_color == 'green':print("Great!You got 5 point!")print("------------------------------------")#5.4
alien_color = 'green'
if alien_color == 'green':print("Great!You got 5 point!")else:print("Excellent!You got 10 point!")
alien_color= 'red'
if alien_color == 'green':print("Great!You got 5 point!")else:print("Excellent!You got 10 point!")print("-----------------------------------------")#5.5
alien_color = 'green'
if alien_color == 'green':print("Great!You got 5 point!")elif alien_color == 'yellow':print("Excellent!You got 10 point!")elif alien_color == 'red':print("Oh,my god!You got 15 point!")
alien_color= 'yellow'
if alien_color == 'green':print("Great!You got 5 point!")elif alien_color == 'yellow':print("Excellent!You got 10 point!")elif alien_color == 'red':print("Oh,my god!You got 15 point!")
alien_color= 'red'
if alien_color == 'green':print("Great!You got 5 point!")elif alien_color == 'yellow':print("Excellent!You got 10 point!")elif alien_color == 'red':print("Oh,my god!You got 15 point!")print("-----------------------------------------")#5.6
age = 33
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("成年人")elif age>=65:print("老年人")#5.7
favourite_fruits = ['apple','banana','orange']if 'apple' infavourite_fruits:print("You really like apples!")if 'banana' infavourite_fruits:print("You really like bananas!")if 'orange' infavourite_fruits:print("You really like orange!")if 'watermalen' infavourite_fruits:print("You really like watermalen!")if 'grape' infavourite_fruits:print("You really like grape!")
如果觉得《python快速编程入门课后题答案-《Python编程:从入门到实践》第五章 if语句 习题答案...》对你有帮助,请点赞、收藏,并留下你的观点哦!