python flow control statements a number of branches

### more branches

"" "
Syntax:
IF conditional expressions 1:
code ...
code ...
elif conditional expression 2:
code ...
code ...
elif conditional expression 3:
code ...
code ...
the else:
code ...
code ...

If the conditional expression 1 is satisfied, which executes a code block, if not true, execute down
if the conditional expression 2 is satisfied, which executes the code block 2, if not true, execute down
if the conditional expression 3 establishment, 3 block of code which, if not true, execute down
until the last, neither condition is met, else the direct implementation of the branch;

Is selected from a plurality of conditions from among the branches;

elif may be 0 or may be a plurality
else may be 0 or may be a
"" "

youqian = True

Double-entry branch

youqian == True IF:
Print ( "I marry you immediately, formalities")
the else:
Print ( "You're a good man ...")

A number of branches

= True youqian
youfang = True
youche = True
youyanzhi = True
youtili = True

youqian == False IF:
Print ( "I will marry you 1")
elif youfang == False:
Print ( "I will marry you 2")
elif youche == False:
Print ( "I will marry you 3" )
elif youyanzhi == False:
Print ( "I will marry you 4")
elif youtili == False:
Print ( "I will marry you 5")
the else:
Print ( "you become a monk, right, when I put on a wedding dress you also put on a robe. ")

### nested branch (branch number of individual branch double entry nested inside each branch)

youqian == True IF:
IF youfang == True:
IF youche == True:
IF youyanzhi == True:
IF youtili == False:
Print ( "aging mother want to marry you 111")
the else:
Print ( "Congratulations, you become! my No. 1 spare tire ")

        else:
            print("你太丑,你去奥拉克整一下荣")

the else:
Print ( "You're a good man, it is a 2-way turn right in front of the car, a taxi home.")

The topic and height

Girls find the object

# 男生在1米~1.5米之间 小强 你在哪里?
# 男生在1.5~1.7米之间 没有安全感~
# 男生 1.7~ 1.8米之间 帅哥 留个电话
# 男生 1.8~2米之间 帅哥 你建议多一个女朋友吗

print("<================>")
'''

Method One: python-specific wording:

height = 1.7

IF 1 <= height <= 1.5:
Print ( "? Xiaoqiang where are you")
elif 1.5 <height <= 1.7:
Print ( "insecure ~")
elif 1.7 <height <= 1.8:
Print ( "guy to leave phone ")
elif 1.8 <height <= 2:
Print (" guy you suggest one more girlfriend ")
the else:
Print (" did not meet the conditions ")
'' '

Method Two: General writing:

height = float (input ( "Please enter your height:"))

print(height,type(height) )

IF height> = 1 and height <= 1.5:
Print ( "Xiaoqiang where are you?")
elif height> 1.5 and height <= 1.7:
Print ( "insecure ~")
elif height> 1.7 and height <= 1.8:
print ( "leave a phone guy")
elif height> 1.8 and height <= 2:
print ( "guy you suggest more than a girlfriend")
the else:
print ( "did not meet the conditions")

Previous next action shortcuts

ctrl + z

ctrl + y

Notes Shortcuts

ctrl + q notepad

ctrl + / pycharm # ### more branches

"" "
Syntax:
IF conditional expressions 1:
code ...
code ...
elif conditional expression 2:
code ...
code ...
elif conditional expression 3:
code ...
code ...
the else:
code ...
code ...

If the conditional expression 1 is satisfied, which executes a code block, if not true, execute down
if the conditional expression 2 is satisfied, which executes the code block 2, if not true, execute down
if the conditional expression 3 establishment, 3 block of code which, if not true, execute down
until the last, neither condition is met, else the direct implementation of the branch;

Is selected from a plurality of conditions from among the branches;

elif may be 0 or may be a plurality
else may be 0 or may be a
"" "

youqian = True

Double-entry branch

youqian == True IF:
Print ( "I marry you immediately, formalities")
the else:
Print ( "You're a good man ...")

A number of branches

= True youqian
youfang = True
youche = True
youyanzhi = True
youtili = True

youqian == False IF:
Print ( "I will marry you 1")
elif youfang == False:
Print ( "I will marry you 2")
elif youche == False:
Print ( "I will marry you 3" )
elif youyanzhi == False:
Print ( "I will marry you 4")
elif youtili == False:
Print ( "I will marry you 5")
the else:
Print ( "you become a monk, right, when I put on a wedding dress you also put on a robe. ")

### nested branch (branch number of individual branch double entry nested inside each branch)

youqian == True IF:
IF youfang == True:
IF youche == True:
IF youyanzhi == True:
IF youtili == False:
Print ( "aging mother want to marry you 111")
the else:
Print ( "Congratulations, you become! my No. 1 spare tire ")

        else:
            print("你太丑,你去奥拉克整一下荣")

the else:
Print ( "You're a good man, it is a 2-way turn right in front of the car, a taxi home.")

The topic and height

Girls find the object

# 男生在1米~1.5米之间 小强 你在哪里?
# 男生在1.5~1.7米之间 没有安全感~
# 男生 1.7~ 1.8米之间 帅哥 留个电话
# 男生 1.8~2米之间 帅哥 你建议多一个女朋友吗

print("<================>")
'''

Method One: python-specific wording:

height = 1.7

IF 1 <= height <= 1.5:
Print ( "? Xiaoqiang where are you")
elif 1.5 <height <= 1.7:
Print ( "insecure ~")
elif 1.7 <height <= 1.8:
Print ( "guy to leave phone ")
elif 1.8 <height <= 2:
Print (" guy you suggest one more girlfriend ")
the else:
Print (" did not meet the conditions ")
'' '

Method Two: General writing:

height = float (input ( "Please enter your height:"))

print(height,type(height) )

IF height> = 1 and height <= 1.5:
Print ( "Xiaoqiang where are you?")
elif height> 1.5 and height <= 1.7:
Print ( "insecure ~")
elif height> 1.7 and height <= 1.8:
print ( "leave a phone guy")
elif height> 1.8 and height <= 2:
print ( "guy you suggest more than a girlfriend")
the else:
print ( "did not meet the conditions")

Guess you like

Origin www.cnblogs.com/CrownYP/p/11318416.html