Python-流程控制之if判斷

'''語法1:if 條件:    代碼1    代碼2    代碼3    ...'''# age_of_bk=30# print('start...')## inp_age=input('>>>:')# inp_age=int(inp_age)# if inp_age == age_of_bk:#     print('猜對了')## print('emmmm')'''語法2:if 條件:    代碼1    代碼2    代碼3    ...else:    代碼1    代碼2    代碼3    ...'''# age=18# gender='male'# is_beautiful=True# if age >= 18 and age <= 25 and gender == 'male' and is_beautiful:#     print('開始表白')# else:#     print('阿姨好')'''語法3:if 條件1:    代碼1    代碼2    代碼3    ...elif 條件2:    代碼1    代碼2    代碼3    ...elif 條件3:    代碼1    代碼2    代碼3    ...elif 條件4:    代碼1    代碼2    代碼3    ...else:    代碼1    代碼2    代碼3    ...''''''若是:        成績>=90,那麼:優秀       若是成績>=80且<90,那麼:良好       若是成績>=70且<80,那麼:普通       其餘狀況:不好'''# score=input('your score>>:')# score=int(score)# if score >=90:#     print('優秀')# elif score >=80:#     print('良好')# elif score >=70:#     print('普通')# else:#     print('不好')# if 條件1:#     代碼1#     代碼2#     代碼3# if 條件2:#     代碼1#     代碼2#     代碼3'''語法4:if 條件1:    if 條件2:        代碼1        代碼2        代碼3        ...    代碼2    代碼3'''age=18gender='male'is_beautiful=Trueis_successful=Trueif age >= 18 and age <= 25 and gender == 'male' and is_beautiful:    print('開始表白')    if is_successful:        print('在一塊兒')    else:        print('逗你玩~~')else:    print('阿姨好')
相關文章
相關標籤/搜索