zoukankan      html  css  js  c++  java
  • Python入门之流程控制之if判断

    一:缩进(逐行缩进)

       if条件:

         代码1

         if条件2:

           代码2

    二、语法

    1、语法1:

      if 条件:
        代码1
        代码2
        代码3

    age = 60
    is_beautiful = True
    star = '水平座'
    
    if age > 16 and age < 20 and is_beautiful and star == '水平座':
        print('我喜欢,我们在一起吧。。。')
    	print('其他代码.............')
    

    2、语法2:

      if 条件:
         代码1
         代码2
        代码3
      else:
         代码1
         代码2
         代码3
     

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

    3、语法3:

      if 条件1:
        代码1
        代码2
         代码3
      elif 条件2:
        代码1
        代码2
         代码3
      elif 条件2:
        代码1
        代码2
        代码3
      else 条件3:
        代码1

    score = input('请输入您的成绩:') # score="18"
    score=int(score)
    
    if score >= 90:
        print('优秀')
    elif score >= 80:
        print('良好')
    elif score >= 70:
        print('普通')
    else:
        print('很差,小垃圾')
    

     

    '''
    if嵌套if
    '''
    age = 17
    is_beautiful = True
    star = '水平座'
    
    if 16 < age < 20 and is_beautiful and star == '水平座':
        print('开始表白。。。。。')
        is_successful = True
        if is_successful:
            print('两个从此过上没羞没臊的生活。。。')
    else:
        print('阿姨好,我逗你玩呢,深藏功与名')
    	print('其他代码.............')
    
  • 相关阅读:
    9、 vector与list的区别与应用?怎么找某vector或者list的倒数第二个元素
    8、STL的两级空间配置器
    hdoj--1342--Lotto(dfs)
    FZU--2188--过河(bfs暴力条件判断)
    zzuli--1812--sort(模拟水题)
    hdoj--3123--GCC(技巧阶乘取余)
    zzulioj--1089--make pair(dfs+模拟)
    zzulioj--1815--easy problem(暴力加技巧)
    zzulioj--1801--xue姐的小动物(水题)
    HIToj--1076--Ordered Fractions(水题)
  • 原文地址:https://www.cnblogs.com/Lance-WJ/p/12432995.html
Copyright © 2011-2022 走看看