3.1 If process judgment
3.1.1 If Else process judgment
#! Author:lanhan
_username = ' Lanhan '
_password = ' 123 '
Username = input ("username:")
Password = input ("password:")
if username = = _username and Password = = _password:
Print ("Welcome user {Name} login ...". Format (name=username))
Else:
Print ("Invalid username or password!")
3.1.2if...elif...else process judgment
#! Author:lanhan
Age_of_oldboy = 56
guess_age = Int (input ("Guess Age:"))
if guess_age = = Age_of_oldboy:
Print ("Yes,you got it.")
elif guess_age > Age_of_oldboy:
Print ("think smaller ...")
Else:
Print ("Think bigger!:")
3.2 While process judgment
3.2.1while True
Example 1:
#! Author:lanhan
Count = 0
While True:
Print ("Count:", Count)
Count = Count +1
if count = = 3:
Break
Example 2:
#! Author:lanhan
count = 0
Age_of_oldboy = A.
while True :
if count = = 3:
break
guess_age = Int (input ( "Guess Age:" )
if guess_age = = Age_of_oldboy:
print ( "Yes,you got it." )
break
elif guess_age > Age_of_oldboy:
Print ( "think smaller ..." )
else :
print ( "Think bigger!:" )
Count +=1
3.2.2while...else
Example 1:
#! Author:lanhan
Count = 0
Age_of_oldboy = 56
whileCount < 3:
guess_age = Int (input ("Guess Age:"))
ifGuess_age = = Age_of_oldboy:
Print"Yes,you got it.")
Break# # # # #不往下走了, jump right out of the loop
elifGuess_age > Age_of_oldboy:
Print"Think smaller ...")
Else:
Print"Think bigger!:")
Count +=1
Else:
Print"You have tried too many times. Fuck off ")
3.3 For process judgment
3.3.1 for i in variable
Example 1:
#! Author:lanhan
for I in range (0,10,2):
If i < 3:
Print ("loop", i)
Else :
Continue # # # #跳出本次循环, continue the next cycle
Print ("hehe ...")
3.3.2for...else
Example 1:
#! Author:lanhan
Count = 0
Age_of_oldboy = 56
for I in range (3):
guess_age = Int (input ("Guess Age:"))
if guess_age = = Age_of_oldboy:
Print ("Yes,you got it.")
Break
elif guess_age > Age_of_oldboy:
Print ("think smaller ...")
Else:
Print ("Think bigger!:")
Else:
Print ("You have tried too many times. Fuck off ")
Python's Path -03-python syntax