Lesson2
conditional statements in Python Applications
In Python, conditional statements are used to make logical decisions
based on the fulfillment of a specific condition.
These statements tell the program to execute a specific part of the code only if
the condition is true.
• what is the Conditional Statement: A conditional statement is a programming
construct that allows a program to choose between several paths of
execution based on specified conditions .
General Syntax for a Conditional Statement:
if condition:
If the condition is true
execute this code ………………..
else
Otherwise execute this code instead ………….
Types of Conditional Statements in Python:
1- If ….. statement :
Example
age = 18
if age >= 18
Print(“you can Enter”)
2- If……else statement:
Example
Age =16
If age >=18
Print(“you can Enter”)
Else:
Print(“you could not Enter”)
3- if ...elif ...else statement:
example
mark = 85
if mark >= 90:
print("Excellent")
elif mark >= 75:
print("Very Good")
elif mark >= 60:
print("Good")
else:
print("Failed")
Practical example
number = int(input("Enter a number: "))
if number > 0:
print("The number is positive")
elif number < 0:
print("The number is negative")
else:
print("The number is zero")