python第五章习题

5-1

animal = 'tiger'
print("Is animal == tiger? I predict Ture.")
print(animal == "tiger")

print("\nIs animal == lion? I predict False")
print(animal == "lion")

输出结果:

Is animal == tiger? I predict Ture.
True

Is animal == lion? I predict False
False

5-5

color = "green"
if color == "green":
	print("you get 5 points.")
elif color == "yellow":
	print("you get 10 points.")
else:
	print("you get 15 points.")

color = "yellow"
if color == "green":
	print("you get 5 points.")
elif color == "yellow":
	print("you get 10 points.")
else:
	print("you get 15 points.")

color = "red"
if color == "green":
	print("you get 5 points.")
elif color == "yellow":
	print("you get 10 points.")
else:
	print("you get 15 points.")

输出结果:

you get 5 points.
you get 10 points.
you get 15 points.

5-7

favorite_fruits = ['apple','banana','watermelon']

if 'apple' in favorite_fruits:
	print("you really like apple.")

if 'pineapple' in favorite_fruits:
	print("you really like pineapple.")

if 'banana' in favorite_fruits:
	print("you really like banana.")

if 'watermelon' in favorite_fruits:
	print("you really like watermelon.")

if 'pear' in favorite_fruits:
	print("you really like pear.")

输出结果:

you really like apple.
you really like banana.
you really like watermelon.

5-10

current_users = ['admin','Kangkang','Mike','Jake','Quinlan']
new_users = ['Kangkang','Helen','MIKE','Faker','Uzi']

current_users_upper = []

for user in current_users:
	current_users_upper.append(user.upper())

for user in new_users:
	if user.upper() in current_users_upper:
		print(user + " is used,please enter another name!")
	else:
		print(user + " can be used.")

输出结果:

Kangkang is used,please enter another name!
Helen can be used.
MIKE is used,please enter another name!
Faker can be used.
Uzi can be used.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值