zoukankan      html  css  js  c++  java
  • python-用户输入和while循环

    函数input()

    比较大小要同类型:

    • age=iput()
    • 21
    • age=int(age)
    • age>=10
    • true
    1 prompt = "If you tell us who you are, we can personalize the messages you see."
    2 prompt += "
    What is your first name? "
    3 #运算符+=在存储prompt中的字符串末尾附加一个字符串。其实可以这样理解:prompt + = '
    zifuchuang'+
    4 name = input(prompt)
    5 print("
    Hello, " + name + "!")

    求模运算符:两个数相除并返回余数。

    1 number = input("Enter a number, and I'll tell you if it's even or odd: ")
    2 print(type(number))  #输入为str
    3 number = int(number)
    4 print(type(number))  #转换为int
    5 if number % 2 == 0:
    6     print("
    The number " + str(number) + " is even.")
    7 else:
    8     print("
    The number " + str(number) + " is odd.")

    while循环

    while 判断条件:

      执行条件

    在循环中使用continue:执行余下的代码并推出整个循环,执行continue语句,让python忽略余下的代码,并返回到循环的开头。

  • 相关阅读:
    视频解析小技巧
    linux系统路由设置
    tracert路由跟踪命令
    php+nginx
    docker快速拉取镜像
    linux命令
    添加docker命令
    linux模糊查询文件名
    查看日志
    模板函数与模板类
  • 原文地址:https://www.cnblogs.com/BBS2013/p/12757458.html
Copyright © 2011-2022 走看看