zoukankan      html  css  js  c++  java
  • 判断条件

    Python 类型有:整数(int),小数(float),字符串(string)

    “ X” 加引号的都为字符串

    Python判断

    if ,elif: else:(只用这三种判断)

    eg:

    age =18

    if age>=18:

      print('成年人')

    else:

      print('未成年')

    判断:

    <,>,<=,>=,==,!=

    and(并且关系)

    eg:

     1     # 功能
     2     # >=90优秀    <=90 >=80为良好, >= 60 <= 80 为及格,<= 60 不及格,不在1- 
     3         100之间提示不合法
     4 
     5 secore = float(input('请输入分数:'))  #input输出的都是字符串,需要转换成int 或者float类型
     6 if secore>= 90 and secore<= 100:
     7     print('优秀')
     8 elif secore< 90 and secore>= 80:
     9     print('良好')
    10 elif secore< 80 and secore>= 60:
    11     print('及格')
    12 elif secore<60 and secore>=0:
    13     print('不及格')
    14 else:
    15     print('不合法')

    or(或者)

    eg:

    1 sex=input('请输入性别(只能输入男,女):')
    2 if sex == ''or sex =='':
    3      print('性别正常')
    4 else:
    5     print("无别识别性别")
    View Code

    判断某一个数据是否存在

    语句 :if  ...in ...

    eg:

    1 user = input('请输入账号:')
    2 if '123456'in user or '111111'in user or '121212'in user:
    3     print('已存在')
    4 else:
    5     print('不存在')

    如果不存在某个数据

    if....not in ...

    user = input('请输入账号:')
    if '123456' not in user and '111111' not in user and '121212' not in user:
        print('可以注册')
    else:
        print('已经注册,不能重复注册')
  • 相关阅读:
    TSQL 备份和还原
    SQL检查死锁情况
    局域网中“隐身”妙招 类似360的局域网隐身
    注册edu邮箱的办法
    C#读、写、删除注册表
    SQL备份计划
    GridView命令不够用怎么办?
    从智能设备访问SQL2000的数据
    智能设备访问SQL2000(一)
    字符HTML编码类(转)
  • 原文地址:https://www.cnblogs.com/xxxxyanyan/p/12752594.html
Copyright © 2011-2022 走看看