python flow control statements

### Process Control

"" "
Process: Process code execution
flow control: the execution of the code is a control flow control

1. sequential structure: default code executed from top to bottom
2. The branch structure: four kinds
3 loop structure: for ... in .. while loop

Branch structure:
1. individual branch
2. Dual item branches
3. The number of branch
4 branches nested
"" "

1. Individually branch

"" "
IF conditional expression:
code1
code2
... ...

If the conditional expression returns True, condition is satisfied, the execution code block, otherwise not executed
"" "

user_name = "fairies"
IF user_name == "fairy":
Print ( "buy her delicious")
Print ( "bought her a drink")
Print ( "bought her playful")
Print ( "Please he ate KFC, McDonald's, Pizza Hut, Amici, Haagen Dazs, Starbucks, Wanda Cinema, the park .. grove ")

2. The two-way branch

"" "
IF conditional expression:
code1 ..
code2 ..
the else:
code3 ..
code4 ..

If the condition expression is established, if the corresponding execution code block
if the conditional expression is not satisfied, the corresponding block of code executed else

if the code block, also known as true interval
else block, also known as false interval
"" "

user_name = "old witch"

if user_name == "old goblin":
Print ( "magic mirror to take you received ..")
the else:
Print ( "you buy a bag, as a cure-all.")

Wait for user input string is a string accepted

res = input ( "Beijing welcome you?")

print(res , type(res))

'' '
Prompts the user to enter a user name and password:
If the username is admin, and the password is 000,
prompting the user to congratulate you, the successful landing
or prompt the user name or password is incorrect
' ''

user = input ( "Please enter your user name:")
password = the INPUT ( "Please enter your password:")
IF the User == "ADMIN" and password == "000":
Print ( "Congratulations, successful landing ")
the else:
Print (" user name or password is incorrect ")

Guess you like

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