python作业(4)

5-2 更多地条件测试:

    代码如下:

str1="AAAA"
str2="BBBB"
str3="AAAA"
print("str1==str2?  "+str(str1==str2))
print("str1==str3?  "+str(str1==str3))
num1=10
num2=60
num3=10
print(num1==num3 and str1==str2)
print(num1==num3 or str1==str2)
nums=[10,20,30,40]
print ( num1 in nums)
print(num2 not in nums)


    运行结果:

    


5-4 外星人颜色#2:

    代码如下:

saucers=['green','blue']
for s in saucers:
	print("The colour of saucer man that you killed is "+s+". ",end=" ")
	if s=='green':
		print("You got 5 points!")
	else:
		print("You got 10 points!")



    结果如下:

    


5-5 外星人颜色#3:

     代码如下:

saucers=['green','yellow','red']
for s in saucers:
	print("The colour of saucer man that you killed is "+s+". ",end=" ")
	if s=='green':
		print("You got 5 points!")
	elif s=='yellow':
		print("You got 10 points!")
	elif s=='red':
		print("You got 15 points!")



    结果如下:

    


5-8 以特殊方式跟管理员打招呼:

    代码如下:

saucers=['Lily','Jojo','Bob','admin','Mike']
for s in saucers:
	if s=='admin':
		print("Hello admin, would you like to see a status report?")
	else:
		print("Hello "+s+", thank you for logging in again.")

    结果如下:

    


5-9 处理没有用户的情形:

    代码如下:

saucers=['Lily','Jojo','Bob','admin','Mike']
saucers.clear()
if len(saucers)==0:
	print("We need to find some users!")
else:
	for s in saucers:
		if s=='admin':
			print("Hello admin, would you like to see a status report?")
		else:
			print("Hello "+s+", thank you for logging in again.")



    结果如下:

    


5-10 检查用户名:

    代码如下:

def check(a,users):
	for b in users:
		if(a.upper()==b.upper()):
			return False
	return True


current_users=['Lily','Jojo','Bob','John','Mike']
new_users=['JOHN','Judy','Lisa','Bob','James']
for s in new_users:
	if check(s,current_users):
		print("This name isn't used.")
	else:
		print("This name has been used. You need to input another one.")



    结果如下:

    





    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值