《高级编程技术》作业[5]——第五章部分习题选做

#5-7
favorite_fruits = ['apple', 'banana', 'pinanapple', 'microsoft', 'orange']
if 'apple' in favorite_fruits:
    print('You really like apple!')
if 'Banana' in favorite_fruits:
    print("You really like bannaa!")
if 'google' in favorite_fruits:
    print('You really like apple!')
if 'steam' in favorite_fruits:
    print("You really like bannaa!")
if 'orange' in favorite_fruits:
    print('You really like apple!')
print("\n")

#5-8
names = ['thinker', 'bai', 'bus driver', 'admin', 'ryoma']
for name in names:
    if name == 'admin':
        print("Hello admin, would you like to see a status report?")
    else:
        print("Hello " + name.title() + ", thank you for logging in again.")
print("\n")

#5-9
names.clear()
if len(names) == 0:
    print("We need to find some users!")
print("\n")

#5-10
current_users = ['thinker', 'bai', 'bus driver', 'admin', 'ryoma']
new_users = ['good man', 'Bai', 'adMin', 'bad driver', 'phd']
for new_user in new_users:
    if new_user.lower() in current_users:
        print(new_user + " is used")
    else:
        print("OK to use " + new_user)
print("\n")

#5-11 
numbers = range(1, 10)
output = ""
for number in numbers:
    if   number == 1:
        output += '1st '
    elif number == 2:
        output += '2nd '
    elif number == 3:
        output += '3rd '
    else :
        output += str(number) + 'th '
print(output)

输出结果如下:


You really like apple!
You really like apple!


Hello Thinker, thank you for logging in again.
Hello Bai, thank you for logging in again.
Hello Bus Driver, thank you for logging in again.
Hello admin, would you like to see a status report?
Hello Ryoma, thank you for logging in again.


We need to find some users!


OK to use good man
Bai is used
adMin is used
OK to use bad driver
OK to use phd


1st 2nd 3rd 4th 5th 6th 7th 8th 9th

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值