1.while遍历待验证的用户,直至列表为空
#创建待验证用户的列表
unconfirmed_users = ['zhao','qian','sun']
#创建空列表,以便存储验证完成的用户
confirmed_users = []
#while遍历待验证的用户,直至unconfirmed_users为空
while unconfirmed_users:
#待验证的用户从末尾依次提出,并存在current_user
current_user = unconfirmed_users.pop()
print("The user has been confirmed:"+current_user)
#验证完成的用户添加到已验证用户(confirmed_users)列表中
confirmed_users.append(current_user)
print("\nThe follow users has been confirmed:")
#遍历验证完成的用户并输出
for confirmed_user in confirmed_users:
print(confirmed_user.title())
The user has been confirmed:sun
The user has been confirmed:qian
The user has been confirmed:zhao
The follow users has been confirmed:
Sun
Qian
Zhao
2.创建空字典,通过while循环以及键和值添加到字典
#使用用户输入创建字典
#创建空字典
responses = {}
#设置循环标志
polling_active = True
while polling_active:
name = input("\nwhat's your name?")
response = input("what's your favourite star?")
#通过键和值添加到字典
responses[name] = response
repeat = input("would you like to let others answer the question?(yes/no)")
#是否进行循环
if repeat == 'no':
polling_active = False
print("_________________________________")
for name, response in responses.items():
print(name+" favourite staer is "+response)
what's your name?daming
what's your favourite star?chenglong
would you like to let others answer the question?(yes/no)yes
what's your name?lingling
what's your favourite star?yaoming
would you like to let others answer the question?(yes/no)no
_________________________________
daming favourite staer is chenglong
lingling favourite staer is yaoming
python的学习还是要多以练习为主,想要练习python的同学,推荐可以去看,他们现在的IT题库内容很丰富,属于国内做的很好的了,而且是课程+刷题+面经+求职+讨论区分享,一站式求职学习网站,最最最重要的里面的资源全部免费。
他们这个python的练习题,知识点编排详细,题目安排合理,题目表述以指导的形式进行。整个题单覆盖了Python入门的全部知识点以及全部语法,通过知识点分类逐层递进,从Hello World开始到最后的实践任务,都会非常详细地指导你应该使用什么函数,应该怎么输入输出。
牛客网(牛客网 - 找工作神器|笔试题库|面试经验|实习招聘内推,求职就业一站解决_牛客网)还提供题解专区和讨论区会有大神提供题解思路,对新手玩家及其友好,有不清楚的语法,不理解的地方,看看别人的思路,别人的代码,也许就能豁然开朗。
快点击下方链接学起来吧!