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 语言一样。
  • 相关阅读:
    返回顶部
    判断元素在数组中
    Vue.js相关知识4-路由
    Vue.js相关知识3-路由
    Vue.js相关知识2-组件
    Vue.js相关知识1
    element表格左右滚动条在总计的上面怎么解决
    JAVA的安装及配置环境变量
    uni-app中使用vuex
    前端常用设计模式
  • 原文地址:https://www.cnblogs.com/A-Tree/p/13293689.html
Copyright © 2011-2022 走看看