Placeholder Image

字幕列表 影片播放

  • in this lesson, we'll learn an elegant way of adding a second if statement to one of our expressions.

  • This is done with the help of the LF keyword, as shown in this example, if why is not greater than five?

  • The computer will think else.

  • If why is less than five written?

  • LF why is less than five?

  • Then I will print out less and the L statement follows as a tell with the respect of Block that says Return equal.

  • Let's confirm we wrote the code correctly.

  • We can print out there compared to five function with a value of Y equal to 10 in the following way.

  • Then we'll expect to see a statement that says greater because tin is greater than five.

  • Correct.

  • Okay, Perfect.

  • What if we carry out this operation for the number two?

  • The machine tells us that too is less than five.

  • And that's what we expected to obtain the third outcome.

  • We must compare the number five with a number that is not greater or smaller than five.

  • This will happen on Lee if the argument of the function is five.

  • Right?

  • Shall we try this one?

  • Great.

  • We obtained equal as expected.

  • I know that you can add as many LF statements as you need.

  • Let's provide an example if why is less than zero?

  • The string negative should be displayed.

  • I will place the block between the if and the other.

  • LF statement Let's see what happens.

  • The function with an argument of minus three shows negative, just as it should.

  • Let me just control whether our little program will run properly.

  • If I asked it to compare to five a value that lies in the range between zero and five, say three.

  • Yes, we see less.

  • So everything is okay.

  • A very important detail you should try to remember is the computer always reads your commands from top to bottom, regardless of the speed at which it works.

  • It executes on Lee one command at a time.

  • Scientifically speaking, the instructions we give to the machine are part of a control flow.

  • This is something like the flow of the logical thought of the computer, the way the computer thinks step by step, executing the steps in a rigid order when it works with the conditional statement, the computer's task will be to execute a specific command once a certain condition has been satisfied.

  • It will read your commands from the if statement at the top through the hell of statements in the middle to the L statement.

  • At the end, the first moment the machine finds a satisfied condition, it will print the respect of output and will execute no other part of the code from this conditional.

  • In our example, if the first statement is correct, we will see the corresponding output number one which is printing the string.

  • Greater.

  • The computer will disregard the LF in the l statements and we'll proceed with the rest of the code.

  • If the first statement is not correct, we will move forward and the computer will check whether our second statement is true.

  • If yes, we'll see Output number two, which is printing the string Negative.

  • If not, we will get to statement number three and so on.

  • Until the computer finds a satisfactory outcome to print out.

  • Now, I will switch the order of the two LF statements to prove that the order of instructions matters Okay, let me print compared to five of minus three, huh?

  • Instead of negative, we obtained Les.

  • This is how the computer reasons.

  • Assume why equals minus three printout Greater if why is greater than five?

  • Is it greater than five?

  • No.

  • So the computer continues and checks.

  • If there are any other statements in our code given we have other statements, it moves forward.

  • So is why less than five?

  • Yes, it is.

  • At this moment, the computer thinks lovely.

  • I got it.

  • My number is less than five.

  • I satisfy what my programmer asked me to do.

  • I print out less, and I am fine.

  • And the machine stops there and does not execute a single letter of the code that follows in this block.

  • The fact that you examine the cases when why is less than zero or equal precisely to five have no application.

  • They become useless.

  • Whether you ask for the output of minus three or three, you will still have to be satisfied with the less label.

  • You found this interesting.

  • Didn't you stay focused for the next lecture when we will share something, Maura, about computational logic.

in this lesson, we'll learn an elegant way of adding a second if statement to one of our expressions.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

A2 初級

ELIF關鍵字[Python基礎知識]。 (The ELIF keyword [Python Fundamentals])

  • 8 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字