流程控制之if判斷

1.什麼是if判斷微信

       判斷一個條件若是成立則作...不成立則作...spa

2.爲什麼要有if判斷code

       讓計算機可以像人同樣具備判斷的能力input

3.如何用if判斷語法

'''計算機

#語法1:co

'''if判斷

if 條件1:

    code1

    code2

    code3

    .......

'''

age=18

if age != 18:

    print('你好啊小夥子')
    print('加個微信吧...')

print('other code...')

 

# 語法2:

 

if 條件:

    code1

    code2

    code3

  ......

else:

    code1

    code2

    code3

    ......

#

age=22

sex = 'male'

x='dd'

is cool = True

 

if age>16 and age<25 and\

x='dd' and is cool:

    print('你好')

else:

    print('再見')

 

# 語法3

 

 if 條件1:

    if 條件2:

        code1

        code2

        code3

    code2

    code3

      .......

 

age = 18

sex = 'hemale'

shencai = 'good'

is_beautiful = True

is_rich = True

 

 

if age >16 and age< 25 and sex = 'hemale'\

and shencai = 'good' and is_beautiful:

    print ('表白')

    if is_rich: 

        print('在一塊兒')

    else:

        print('你是誰')

else:

    print('8888888')

 

 

# 語法4

if 條件1:

        子代碼塊1

elif 條件2:

        子代碼塊2

elif 條件3:

        子代碼塊3

elif 條件4:

        子代碼塊4

.............

else:

        子代碼塊5

 

#

score = input('your score:')

score = int(score)

if score >= 90:

    print('A')

elif score >= 80:

    print('B')

elif score >= 70:

    print('C')

else:

    print('laji')

相關文章
相關標籤/搜索