zoukankan      html  css  js  c++  java
  • Python 入门日记(七)—— 用户输入和 while 循环

    2020.07.13 Python 入门的 Day6

    成就:用户输入和 while 循环

    • 函数 input() 可用于读入字符串,使用 input() 读入的数据都被视作字符串。
    message = input("Tell me something, and I will repeat it back to you: ")
    print(message)
    # Tell me something, and I will repeat it back to you: lbwnb
    # lbwnb
    prompt = "If you tell us who you are, we can personalize the messages you see."
    prompt += "
    What is your first name?"
    name = input(prompt)
    # If you tell us who you are, we can personalize the messages you see.
    # What is your first name?lbw
    # >>name:" lbw
    • 如果要读入整数类型,需要读入字符串之后强制类型转换;要读入浮点数也同理。
    • 但如果格式不对,编辑器会报错。
    age = input()
    age = int(age)
    # 读入整数
    age = float(age)
    # 强制转换成浮点数
    • while 循环格式如下:
    counter_number = 1
    Active = True
    
    while Active:
        counter_number += 1
        if counter_number >= 100:
            Active = False
        if counter_number == 89:
            break
    • break、continue 的使用与 C 语言一样。
  • 相关阅读:
    HDU 3709 Balanced Number
    HDU 3652 B-number
    HDU 3555 Bomb
    全局和局部内存管理
    [转]
    [转]
    [转]
    The Stable Marriage Problem
    STL各种容器的使用时机详解
    Qt中图像的显示与基本操作
  • 原文地址:https://www.cnblogs.com/A-Tree/p/13293689.html
Copyright © 2011-2022 走看看