python从入门到实践-7章用户输入和while循环

#!/user/bin/env python
# -*- coding:utf-8 -*-

# input() 可以让程序暂停工作
# int(input('please input something:'))
# % 取余运算


# 【标识符】
# prompt = "\n Tell me something,and i will repeat it back to you:"
# message = ""
#
# active = True
# while active:
# message = input(prompt)
# if message == 'quit':
# active = False
# else:
# print(message)

# break 退出循环
# continue 终止当前循环(跳过本次)
# 无限循环 Ctrl + c 关闭显示窗口
"""
for循环中不应修改列表。否则将导致Python难以跟踪其中的元素,使用while循环进行修改。
"""

# 列表之间移动元素
unconfirmed_user = ['alice','brian','candace']
confirmed_users = []
while unconfirmed_user:
current_user = unconfirmed_user.pop()
print("Verifying user: " + current_user.title())
confirmed_users.append(current_user)
print("\nThe following users have been confired:")
for confirmed_user in confirmed_users:
print(confirmed_user.title())

# 删除 .pop() .remove()

# 使用用户输入来填充字典
responses = {}
polling_active = True
while polling_active:
name = input("your name:")
response = input("Do you like climb someday?")
responses[name] = response
repeat = input("Any others?(yes/no)")
if repeat == 'no':
polling_active = False
print("*"*50)
for name, response in responses.items():
print(name + "Do you like climb:" + response + "?")

posted @ 2018-10-30 22:17  alfred_hong  阅读(97)  评论(0编辑  收藏  举报