Popular Posts

Thursday, August 27, 2020

Python Beginner: If Statements & Comparisions

 Hello, developer!


Today, we will learn value comparison values in condition of "If Statements".

We can use  number value comparison as below.


Number Value Comparisons

value_1 == value_2 # value_1 and value_2 are same value

value_1 > value_2 # value_1 is greater than value_2

value_1 >=  value_2 # value_1 and value_2 are same or value_1 is greater than value_2

value_1 != value_2 # value_1 is not same value_2


We will use these comparisons in the condition of if statements.


I showed the "If Statements & Comparisons" exercise codes and execution result as following.

def max_num(num1, num2, num3):
if num1 >= num2 and num1 >= num3:
return num1
elif num2 >= num1 and num2 >= num3:
return num2
else:
return num3

print(max_num(300,4,5))

def max_num2(num1, num2, num3):
if num1 == num2 and num1 != num3:
return num1
elif num1 != num2 and num2 == num3:
return num2
else:
return num3

print(max_num2(5,10,15))


Can you see the same result on your PC? Great job! Now you can use number value comparisons in if statements.


See you on next post, developer! 😊



No comments:

Post a Comment

Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...