第五次作业(2018-03-19,周一)

教材第五章习题

5-2

print("huan"=="huan")
print("huang"!="huang")
print("Huan".lower()=="huan")
print("Huang".lower()=="huan")
print(0.2>0.21)
print(-1<=0)
print(6>3 and 6<9)
print("huang"=="Huang" or 0.1==0.10001)
names = ["huang",0.22,'r', "Huang"]
print("huang" in names)

print(0.22 not in names)

5-7

age = 20
if age<2:
print("He is a baby.")
elif age<4:
print("He is learning to walk.")
elif age<13:
print("He is a child.")
elif age<20:
print("He is a teenager.")
elif age<65:
print("He is an adult.")
else:

print("He is an oldman.")

5-8

user_names = ["admin", "huan1", "huan2", "huan3", "huan4"]
for user_name in user_names:
if user_name == "admin":
print("Hello admin, would you like to see a status report?")
else:

print("Hello Eric, thank you for logging in again.")

5-9

user_names = ["admin", "huan1", "huan2", "huan3", "huan4"]
for user_name in user_names:
if user_name == "admin":
print("Hello admin, would you like to see a status report?")
else:
print("Hello Eric, thank you for logging in again.")
if not user_names:
print("We need to find some users.")
user_names = []
if not user_names:

print("We need to find some users.")

5-10

current_users = ["Alice", "Mike", "John", "Jack", "David"]
new_users = ["Lucy", "Lily", "Jack", "Alice", "Eric"]
for i in range(0,len(current_users)):
current_users[i] = current_users[i].lower()
for new_user in new_users:
if(new_user.lower() in current_users):
print("The user name has been used, please use another name.")
else:

print("The name has not been  used yet, you can use it.")

5-11

list = [1,2,3,4,5,6,7,8,9]
for i in list:
if(i==1):
print(i,end="")
print("st")
elif(i==2):
print(i, end="")
print("nd")
elif(i==3):
print(i, end="")
print("rd")
else:
print(i,end="")

print("th")


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值