Boolean operation :and、or、not、in、not in
break sentence : It's used to end the loop , General writing if...break, It is written as follows :
# break The statement is tie-in for loop
for...in...:
...
if ...:
break
# break The statement is tie-in while loop
while...( Conditions ):
...
if ...:
break
if...break If a certain condition is satisfied , Just end the cycle ahead of time . remember , This can only be used inside the loop .
for i in range(5):
print(' Tomorrow is tomorrow ')
if i==3: # When i be equal to 3 Is triggered when
break # End of cycle
continue sentence : When a condition is met , Trigger continue sentence , The following code will be skipped , Go straight back to the beginning of the loop .
# continue The statement is tie-in for loop
for...in...:
...
if ...:
continue
...
# continue The statement is tie-in while loop
while...( Conditions ):
...
if ...:
continue
...
i = 0
while i<5:
print(' Tomorrow is tomorrow ')
i = i+1
if i==3: # When i be equal to 3 Is triggered when
continue # Go back to the beginning of the loop
print(' In this sentence i be equal to 3 I can't print it out ')
pass sentence : It's very simple , Its English meaning is “ skip ”.
else sentence :else Not only can it be with if In combination with , It can also follow for Circulation and while To use in combination with circulation .
Case study : Guess the number game
# Guess the number game
a=24
while True:
b=int(input(' Input number :')
if b>a:
print(' It's too big ')
if b<a:
print(' Is too small ')
if b==a:
print(' Guessed it ')
break
Case study : Just enter the actor's name , Just print out :×× In a movie ××.
movies = {
' Cat pass ':[' Huang Huang ',' Dyed grain will be too '],
' No ask seton hall ':[' Zhang ziyi ',' Wang Lihong ',' Zufeng '],
' Cohabitation beyond time and space ':[' Lei Jia Yin ',' Liyan tong '],
}
name=input(' Please enter the actor name ')
for movie in movies:
actors=movies[movie]
for actor in actors:
if actor==name:
print(name+' In a movie '+movie)