filmov
tv
#10 Python Playground: If Statement | Computer Programming & Coding for Kids & Beginners

Показать описание
Magic10
10-0
Liam
If Statement in Python
10-1
Emma
Hi, Liam!
Liam
Hi, Emma!
Emma
I am not always able to make decisions.
Can I ask Python to make a decision?
Liam
Sure!
Python is very good at making decisions.
Emma
How do we let Python make the decision?
Liam
If you want Python to make a decision, you can use an if statement.
Emma
What is if statement?
Liam
In the if statement, processing is performed if the conditions are met.
Emma
So Python is always able to make a clear decision.
Liam
Exactly!
So let's create a program with an if statement and let Python decide for us!
Emma
I'm looking forward to that.
10-2
Liam
How to Write If Statement
Liam
If statement is divided into two parts: the conditional part and the process part to be performed when it is true.
Emma
Python will determine if that condition is met.
Liam
That’s right.
Emma
How do we write a conditional expression?
Liam
For conditional expressions, we use the comparison operators.
Emma
What are comparison operators?
Liam
Comparison operators in python, also called python relational operator, compares the values of two operands and returns True or False based on whether the condition is met.
Emma
How many comparison operators are there?
Liam
There are six types of comparison operators: equal to, not equal to, less than, less than or equal to, greater than, greater than or equal to.
10-3
Liam
Let's Try If Statement
Liam
Let's make a program that displays "Good job!” and “Keep it up!” when the score is 80 points or more.
Emma
Sounds interesting!
Liam
Open a new file in IDLE and write the code like this
Emma
Do we need an indentation at the beginning of the line below the conditional expression?
Liam
Yes, indentation is necessary.
The same indented area will be a single block.
To indent, put a "tab" or four spaces at the beginning of the line.
However, if you are typing in IDLE, a tab is automatically entered and indented.
When the block is finished and you no longer need the indentation, delete the "tab" yourself.
Emma
I found that I needed to indent to create a single block that does the same process.
Liam
OK!
Save and run this program.
Emma
The score was over 80, so the process was run.
What happens if the score is lower than 80?
Liam
Open a new file in IDLE and write the code like this
Liam
Save and run this program.
Emma
Since the score was lower than 80, it was not processed.
10-4
Liam
If Else Statement in Python
Emma
How can I write a process when the conditions are not met?
Liam
In that case, lets’s use the if else statement.
Let's make a program that displays ”Never mind!” "Better luck next time." when the score is lower than 80 points.
Emma
So if I score lower than 80, the python encourages me.
Liam
That’s right.
Open a new file in IDLE and write the code like this.
Liam
Save and run this program.
Emma
Python encouraged me because my score was below 80 points.
10-5
Emma
In this lesson, we learned about If statement and if else statement in Python,.
Liam
Well done!
10-0
Liam
If Statement in Python
10-1
Emma
Hi, Liam!
Liam
Hi, Emma!
Emma
I am not always able to make decisions.
Can I ask Python to make a decision?
Liam
Sure!
Python is very good at making decisions.
Emma
How do we let Python make the decision?
Liam
If you want Python to make a decision, you can use an if statement.
Emma
What is if statement?
Liam
In the if statement, processing is performed if the conditions are met.
Emma
So Python is always able to make a clear decision.
Liam
Exactly!
So let's create a program with an if statement and let Python decide for us!
Emma
I'm looking forward to that.
10-2
Liam
How to Write If Statement
Liam
If statement is divided into two parts: the conditional part and the process part to be performed when it is true.
Emma
Python will determine if that condition is met.
Liam
That’s right.
Emma
How do we write a conditional expression?
Liam
For conditional expressions, we use the comparison operators.
Emma
What are comparison operators?
Liam
Comparison operators in python, also called python relational operator, compares the values of two operands and returns True or False based on whether the condition is met.
Emma
How many comparison operators are there?
Liam
There are six types of comparison operators: equal to, not equal to, less than, less than or equal to, greater than, greater than or equal to.
10-3
Liam
Let's Try If Statement
Liam
Let's make a program that displays "Good job!” and “Keep it up!” when the score is 80 points or more.
Emma
Sounds interesting!
Liam
Open a new file in IDLE and write the code like this
Emma
Do we need an indentation at the beginning of the line below the conditional expression?
Liam
Yes, indentation is necessary.
The same indented area will be a single block.
To indent, put a "tab" or four spaces at the beginning of the line.
However, if you are typing in IDLE, a tab is automatically entered and indented.
When the block is finished and you no longer need the indentation, delete the "tab" yourself.
Emma
I found that I needed to indent to create a single block that does the same process.
Liam
OK!
Save and run this program.
Emma
The score was over 80, so the process was run.
What happens if the score is lower than 80?
Liam
Open a new file in IDLE and write the code like this
Liam
Save and run this program.
Emma
Since the score was lower than 80, it was not processed.
10-4
Liam
If Else Statement in Python
Emma
How can I write a process when the conditions are not met?
Liam
In that case, lets’s use the if else statement.
Let's make a program that displays ”Never mind!” "Better luck next time." when the score is lower than 80 points.
Emma
So if I score lower than 80, the python encourages me.
Liam
That’s right.
Open a new file in IDLE and write the code like this.
Liam
Save and run this program.
Emma
Python encouraged me because my score was below 80 points.
10-5
Emma
In this lesson, we learned about If statement and if else statement in Python,.
Liam
Well done!
Комментарии