zoukankan      html  css  js  c++  java
  • 基础-if判断

    if 基础语法格式(注意格式--缩进)

    • if 语句 以及 缩进部分可以看成一个 完整的代码块
    age = 18
    if age >= 18:
        print("happy")

    if-延伸-自定义变量类型

    • if 和 else 语句 以及 各自的缩进部分共同是一个 完整的代码块
    • input 用户输入的数据 类型是 str() == 字符串类型  所以要用到类型转换
    age = int(input('请输入年龄:'))
    if age >= 18:
        print('happy')
    else:
        print('go home')

     

    拓展:比较运算符

     

    逻辑运算符

    连接条件

      and  两者都为真才是真

      or     一个为真就为真

    取反

      not  非

    逻辑演练1:

    # 定义一个变量age 编写代码判断年龄是否正确
    age = 1211
    
    # 要求年龄在 0-199 之间
    if age >= 0 and age <= 199:
        print("年龄正确")
    else:
        print("年龄错误")

    逻辑演练2:

    # 定义两个变量 python_score c_score 编写代码判断成绩
    python_score = 20
    c_score = 20
    # 只要一门成绩大于60分就合格 if python_score > 60 or c_score > 60: print("成绩合格") else: print("成绩不合格")

    逻辑演练3:

    • 在开发中,通常希望某个条件不满足时,执行一些代码 可以用not
    • 如果需要拼接复杂的逻辑计算条件,同样也可能使用到 not
    # 定义一个布尔型变量 is_employee,编写代码判断是否是本公司员工
    is_employee = False
    # 如果不是提示不允许入内 if not is_employee: print("非本公司员工,不许入内")

    pycharm小技巧

    选中行 按下 Tab键 会自动缩进

    那么怎么 返回呢 , 只需要 按下 shift + Tab 即可

  • 相关阅读:
    hibernate01
    利用Struts2拦截器完成文件上传功能
    layui的CRUD案例
    最大流dinic模板 poj1273
    CodeForces
    POJ 2139 Six Degrees of Cowvin Bacon (floyd)
    POJ 3259 Wormholes (floyd或者spfa)
    POJ 3615 Cow Hurdles (flyod)
    Codeforces Round #446 (Div. 1) A. Pride
    Educational Codeforces Round 34 A. Hungry Student Problem
  • 原文地址:https://www.cnblogs.com/leading-net/p/12657746.html
Copyright © 2011-2022 走看看