0% found this document useful (0 votes)
7 views2 pages

Conditional Statements in Python Applications

This document explains conditional statements in Python, which are used to execute specific code based on whether a condition is true. It outlines the general syntax and types of conditional statements, including 'if', 'if...else', and 'if...elif...else' statements, with examples for each. Additionally, it provides a practical example of using conditional statements to determine if a number is positive, negative, or zero.

Uploaded by

yasin.hossam.11
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Conditional Statements in Python Applications

This document explains conditional statements in Python, which are used to execute specific code based on whether a condition is true. It outlines the general syntax and types of conditional statements, including 'if', 'if...else', and 'if...elif...else' statements, with examples for each. Additionally, it provides a practical example of using conditional statements to determine if a number is positive, negative, or zero.

Uploaded by

yasin.hossam.11
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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")

You might also like