zoukankan      html  css  js  c++  java
  • 判断语句--if

    缩进

    逐行缩进

      if条件:

        代码1

        if条件2:

          代码2

    语法

    语法1:

      if条件:

        代码1

        代码2

        代码3

    age = 60
    is_beautiful = True
    star = '水瓶座'
    
    if age > 16 and age < 20 and is_beautiful and star == '水瓶座':
        print('我喜欢你,我们在一起吧!')

    语法2:

      if条件:

        代码1

      else:

        代码1

    age = 60
    is_beautiful = True
    star = '水瓶座'
    
    if age > 16 and age < 20 and is_beautiful and star == '水瓶座':
        print('我喜欢你,我们在一起吧!')
    else:
        print('阿姨好,我逗你玩儿呢,深藏功与名')
    print('其他代码')

    语法3:

      if条件:

        代码1

      elif:

        代码1

      else:

        代码1

    score = 63
    
    if score >= 90:
        print('优秀啊,小伙子!')
    elif score >= 80:
        print('还可以吧!')
    elif score >= 60:
        print('要努力了呀,小伙子')
    else:
        print("滚啊!!!")

    改进版:

    score = input('请输入您的成绩:')
    score = int(score)
    
    if score >= 90:
        print('优秀啊,小伙子!')
    elif score >= 80:
        print('还可以吧!')
    elif score >= 70:
        print('要努力了呀,小伙子')
    elif score >= 60:
        print('准备叫家长吧!')
    else:
        print("滚啊!!!"

     

  • 相关阅读:
    模板
    Codeforces Round #598 (Div. 3)
    Codeforces Round #589 (Div. 2)
    日记集
    模板
    Codeforces Round #592 (Div. 2)
    Linux挂载新盘
    VMware实用技巧
    useradd和adduser的区别
    ubuntu VSFTPD搭建FTP服务器 提示530错误
  • 原文地址:https://www.cnblogs.com/zhww/p/12982183.html
Copyright © 2011-2022 走看看