In life, a thing is faced with a lot of choices, such as eating time, will consider what to eat, rice bowls? Noodles? Hot pot? , if you choose to eat rice bowl, what to eat rice bowl, pepper shredded pork? Fish fragrant shredded pork?
You can use Python to do the things described above:
Input_value = input ("Would you like something to eat, rice bowls, noodles, hot pot:")ifInput_value = ='Rice Bowls': Print("you have chosen%s! "%input_value)elifInput_value = ='Noodles': Print("you have chosen%s! "%input_value)elifInput_value = ='Hot Pot': Print("you have chosen%s! "%input_value)Else: Print("you have chosen the%s store no, thank you for coming! "% input_value)
elifis else if the abbreviation, can have more than one elif , so if the complete form of the statement is:
if < condition judgment 1>: < execute 1>elif < condition 2> :< execute 2>elif < condition judgment 3>: < execute 3>else: < Execute 4>
ifStatement execution has a characteristic, it is to judge from the top, if in a certain judgment True , the statement corresponding to the execution of the sentence, will ignore the remaining elif andelse
Flow chart:
Python route-basic-7 pieces judgment