zoukankan      html  css  js  c++  java
  • 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 + "?")

  • 相关阅读:
    DAY13-前端之JavaScript
    DAY12-前端之CSS
    DAY12-前端之HTML
    DAY11-MYSQL之ORM框架SQLAlchemy
    DAY11-MYSQL视图、触发器、事务、存储过程、函数
    DAY11-MYSQL数据备份、pymysql模块
    DAY11-MYSQL索引原理与慢查询优化
    020.2.2 runtime类
    020.2.1 system
    020.1.2 Arrays集合工具类
  • 原文地址:https://www.cnblogs.com/vwei/p/9880001.html
Copyright © 2011-2022 走看看