The syntax is simple python 2

in case():

What execution

otherwise():

doing what

#

If (it does not rain today):

They go play basketball playground dam

If (today's hot):

Invited to ask someone to go Swimming pools

otherwise:

We still handsome man to be quiet classroom lectures on it!

grammar

if (conditional expression):

Block

else:

Block

#

Case:

answer = input ( "ask how the weather like today")

if (answer == 'it does not rain today'):

print ( "we went to the playground to play basketball dam")

if (answer == 'Today the weather is hot'):

print ( "go ask someone to invite Swimming pools")

else:

print ( "I still feel at ease to school now!")

Program is executed from top to bottom, if all if conditions are at the same level, it will next determine if all the statements, we determined that more than if the same conditions,

Should use elif, otherwise the situation will be judged many times!

#

result = int (input ( "Please enter student test scores"))

if(result==100):

print ( "60 minutes" long live)

elif (result >= 90):

print ( "like a general matter")

elif (result >= 80):

print ( "can")

elif(result>=70):

print ( "excellent")

elif(result>=60):

print ( "test tyrants")

else:

( "You're a lovely classmate!")

#

Conclusion: Write program logic important than grammar, how to write logic, a mind map to draw the logic diagram, and then do the replacement program

# Circulation loop condition loop operation

At best not to use, in the end is not clear how many times you want to loop while the situation with

while conditions

Cycle operation

Case #:

answer = input ( "When will the rain stop")

while True:

if (answer == "rain stopped"):

print ( "without the umbrella")

break

else:

print ( "continue to fight your umbrella with you.")

answer = input ( "When will the rain stop")

#

A clear case of how many times the cycle of 95% are used for

for the variable in the sequence (strings, lists, tuples, dictionaries)

for variable in range () function

for i in range(10):

print ( "Please continue your installed operating b!")

if(i==4):

    # print("结束装b")
    # break
    # print("装b装累了,休息一下再继续装b")
    # continue

break is out of the entire cycle, continue to skip this cycle only

Guess you like

Origin blog.51cto.com/983865387/2412547