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


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

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


    # 【标识符】
    # prompt = " 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(" The 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 + "?")

  • 相关阅读:
    SQL语言
    数组的指针
    Java泛型
    python面向对象(下)
    Java枚举类enum
    理解Java的GC日志
    python生成器
    Java并发编程之ThreadLocal类
    python面向对象(上)
    Java并发编程之闭锁简介
  • 原文地址:https://www.cnblogs.com/vwei/p/9880001.html
Copyright © 2020-2023  润新知