Programming in Python (Part-4)

0 Comments

Conditional Statement in Python perform different computations or actions depending on whether a specific Boolean constraint evaluates to true or false. Conditional statements are handled by IF statements in Python.

In this post we will learning about conditional logic/ conditional statements in Python. You can also learn from video tutorial, check out below link https://www.youtube.com/watch?v=hhTO3oP4r6Y

A lot of time we stuck in situation like when this happen do this else do some other task, this is also called decision taking based on certain criteria or conditions.

If..elif..else these statements are used when doing decision making in Python.

Keep in mind below logical symbol and logical operators as they will help in decision making and they can be used with IF statements or LOOPS as well

Symbol Operation
== Equal to
!= Not Equal to
Greater than
Less than
>= Greater than equal to
<= Less than equal to
and (logical operator) When two statements are true
or (logical operator) When one of the statement is true
# Example 1

first_number = input('Enter first number: ')
second_number = input('Enter second number: ')

if first_number > second_number:
    print('First Number is greater')
else:
    print('Second Number is greater')
# Example 2

num = input("Enter a number: ") # input
num = float(num) # typecasts string value into float

if num > 0:
    print("Positive number")

elif num == 0:
    print("Zero")
       
else:
    print("Negative number")

Above example can be useful for implementing conditions in Python
You can find other examples as well on my github page…
https://github.com/uzairaj/Python_Programming

Thank you for reading…


Leave a Reply

Your email address will not be published. Required fields are marked *