The combination of ‘while‘ and ‘list‘

Q1: There is a list contianing the names of the account that has not been verfied. This list is called unconfirmed_users. We should transfer the name in the unconfirmed_users into the confirmed users. And print them out. 

The output:

Verifying user:Candace
Verifying user:Brian
Verifying user:Alice
The following users have been confirmed:
Candace
Brian
Alice

The codes:

unconfirmed_users = ['alice','brian','candace']
confirmed_users = []
while unconfirmed_users:
    user = unconfirmed_users.pop()
    print('Verifying user:' + user.title())
    confirmed_users.append(user)
print('The following users have been confirmed:')
for name in confirmed_users:
    print(name.title())
    

Q 2: Delete a particular element all in a special list:

The original list: ['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'cat']
The new list: ['dog', 'dog', 'goldfish', 'rabbit']

The codes:

pets = ['dog','cat','dog','goldfish','cat','rabbit','cat']
print('The original list: ',end=(''))
print(pets)
while 'cat' in pets:
    pets.remove('cat')
print('The new list: ',end=(''))
print(pets)

Q3: Utilize the dictionary to collect the name compared with mountain he or she loved.

What Is Your Name? sunny

Which mountian would you like to climb someday? Denali
Would you like to let another person respond?(yes/no)

yes

What Is Your Name? Emma

Which mountian would you like to climb someday? Devil's Thumb
Would you like to let another person respond?(yes/no)

no
---Poll Results---
sunnywould like to climbDenali.
Emmawould like to climbDevil's Thumb.

The codes:

responses = {}
polling_avtive = True
while polling_avtive:
    message = 'what is your name? '
    name = input(message.title())
    message1 = 'Which mountian would you like to climb someday? '
    mountain = input(message1)
    responses[name] = mountain
    print('Would you like to let another person respond?(yes/no)')
    repeat = input()
    if repeat.lower() == 'no':
        polling_avtive = False
print('---Poll Results---')
for name,mountain in responses.items():
    print(name + 'would like to climb' + mountain +'.')

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值