Course Content
Conditional Statements in Python
Conditional Statements in Python
Introduction to if Statement
Hello, everyone! I'm delighted to welcome you to this course. Here, we will become familiar with the conditional operator, sometimes referred to as the branch operator.
Let's clarify a bit:
Here, we have the following condition: age > 18
. In our case, age = 20
, and because 20 is greater than 18, the condition is True. So, the code inside the if block is run, and we see the message "You can vote"
. We learned a little bit about the conditional operator, and now let's strengthen our knowledge with simple practice. In the next chapter, we will study the syntax of this construction in more detail.
Example:
age = 20 if age > 18: print('You can vote')
Analysis:
In this case, we have the following condition age > 18
. In our case, age = 20
, and since 20 > 18
, the condition is True, so the code that is written in the if
statement block is executed, and as a result we see "You can vote"
.
We got a little acquainted with the conditional operator, let's strengthen our knowledge with simple practice, and in the next chapter, we will study the syntax of this construction in more detail.
Task
- You have the following string:
string = 'codefinity'
; - Count the length of this string and write the result to the variable
len_of_string
; - Write
if statement
that checks for the following condition: if the string length is greater than 7 , print the following text:Codefinity is the best platform to start your career in IT
.
Fill in the blanks in the code you've already been given.
Once you've completed this task, click the button below the code to check your solution.
Thanks for your feedback!
Introduction to if Statement
Hello, everyone! I'm delighted to welcome you to this course. Here, we will become familiar with the conditional operator, sometimes referred to as the branch operator.
Let's clarify a bit:
Here, we have the following condition: age > 18
. In our case, age = 20
, and because 20 is greater than 18, the condition is True. So, the code inside the if block is run, and we see the message "You can vote"
. We learned a little bit about the conditional operator, and now let's strengthen our knowledge with simple practice. In the next chapter, we will study the syntax of this construction in more detail.
Example:
age = 20 if age > 18: print('You can vote')
Analysis:
In this case, we have the following condition age > 18
. In our case, age = 20
, and since 20 > 18
, the condition is True, so the code that is written in the if
statement block is executed, and as a result we see "You can vote"
.
We got a little acquainted with the conditional operator, let's strengthen our knowledge with simple practice, and in the next chapter, we will study the syntax of this construction in more detail.
Task
- You have the following string:
string = 'codefinity'
; - Count the length of this string and write the result to the variable
len_of_string
; - Write
if statement
that checks for the following condition: if the string length is greater than 7 , print the following text:Codefinity is the best platform to start your career in IT
.
Fill in the blanks in the code you've already been given.
Once you've completed this task, click the button below the code to check your solution.
Thanks for your feedback!
Introduction to if Statement
Hello, everyone! I'm delighted to welcome you to this course. Here, we will become familiar with the conditional operator, sometimes referred to as the branch operator.
Let's clarify a bit:
Here, we have the following condition: age > 18
. In our case, age = 20
, and because 20 is greater than 18, the condition is True. So, the code inside the if block is run, and we see the message "You can vote"
. We learned a little bit about the conditional operator, and now let's strengthen our knowledge with simple practice. In the next chapter, we will study the syntax of this construction in more detail.
Example:
age = 20 if age > 18: print('You can vote')
Analysis:
In this case, we have the following condition age > 18
. In our case, age = 20
, and since 20 > 18
, the condition is True, so the code that is written in the if
statement block is executed, and as a result we see "You can vote"
.
We got a little acquainted with the conditional operator, let's strengthen our knowledge with simple practice, and in the next chapter, we will study the syntax of this construction in more detail.
Task
- You have the following string:
string = 'codefinity'
; - Count the length of this string and write the result to the variable
len_of_string
; - Write
if statement
that checks for the following condition: if the string length is greater than 7 , print the following text:Codefinity is the best platform to start your career in IT
.
Fill in the blanks in the code you've already been given.
Once you've completed this task, click the button below the code to check your solution.
Thanks for your feedback!
Hello, everyone! I'm delighted to welcome you to this course. Here, we will become familiar with the conditional operator, sometimes referred to as the branch operator.
Let's clarify a bit:
Here, we have the following condition: age > 18
. In our case, age = 20
, and because 20 is greater than 18, the condition is True. So, the code inside the if block is run, and we see the message "You can vote"
. We learned a little bit about the conditional operator, and now let's strengthen our knowledge with simple practice. In the next chapter, we will study the syntax of this construction in more detail.
Example:
age = 20 if age > 18: print('You can vote')
Analysis:
In this case, we have the following condition age > 18
. In our case, age = 20
, and since 20 > 18
, the condition is True, so the code that is written in the if
statement block is executed, and as a result we see "You can vote"
.
We got a little acquainted with the conditional operator, let's strengthen our knowledge with simple practice, and in the next chapter, we will study the syntax of this construction in more detail.
Task
- You have the following string:
string = 'codefinity'
; - Count the length of this string and write the result to the variable
len_of_string
; - Write
if statement
that checks for the following condition: if the string length is greater than 7 , print the following text:Codefinity is the best platform to start your career in IT
.
Fill in the blanks in the code you've already been given.
Once you've completed this task, click the button below the code to check your solution.