PratyushPaul PYTHONCA1
PratyushPaul PYTHONCA1
CONDITIONAL STATEMENTS IN
PYTHON AND THEIR USE
Presented By :-
Output
x is greater than 5
The 'if-else' Statement
The else statement provides an alternative block of code that
executes when the if condition is false. This is useful for defining a
default action when no conditions are met, enhancing program
control.
Output
Output
x is equal to 5
Nested Conditional Statements
Output
Basic Syntax
Output
Adult
Logical Operators in Conditional Statements
AND Operator
Both conditions must be true. Example:
if x >5 and x <10: print("In range")
OR Operator
Only one condition needs to be true.
Example: if x <5 or x >10: print("Out of
range") Output
== Equal to X==10
Finally, the code prints out the grade. This example illustrates how
conditional statements can be used to categorize or make decisions
based on numerical values, showcasing a real-world application of
these concepts.
Output
Your grade is B
Best Practices for Conditional
Conditional Statements
Keep conditions simple Use descriptive names
Avoid complex conditions, use Name your variables clearly to
multiple statements instead. enhance readability.