#避免无限循环'''x=1
while x<5:
print(x)
x+=1'''#不递增会无限循环#使用while循环处理列表和字典#在列表间移动元素#例子 假设有一个列表包含新注册但还未验证的网站用户。unconfirmed_users = ['alice', 'brian', 'candace']#验证这些用户后,如何将他们移到另一个已验证用户列表中呢?confirmed_users = []'''unconfirmed_users=['alice','brian','candace']#创建未验证用户列表
confirmed_users=[]#用于储存以验证用户的控列表
while unconfirmed_users:#当列表为空时结束
current_user=unconfirmed_users.pop()#pop()每次从列表末尾弹出一个值
print(f"已经验证用户:{current_user.title()}")
confirmed_users.append(current_user)#将验证的用户赋值给空列表
print("\n这些用户已经验证:")
for confirmed_user in confirmed_users:
print(confirmed_user.title())'''#将已经验证用户显示出来#删除为特定值的所有列表元素 remove()#移除cat'''pets=['dog','cat','dog','cat']
print(pets)
while 'cat' in pets:
pets.remove('cat')
print(pets)'''#使用用户输入来填充字典#例子 询问用户名称和想去的山#注意字典是不能单独被循环读取,需要使用items()'''response={}
q=1
while q:
name=input("\n你的名字是?")
mountain_name=input("你想去那座山呢?")
response[name]=mountain_name#输出结果格式为name:mountain_name
repeat=input("还有其他人想参与调查吗?")
if repeat=='no':
q=0
print("\n调查结果")
for name,mountain_name in response.items():
print(f"{name}想要去{mountain_name}。")'''