Exp 2
Exp 2
Experiment No.02
A.1 Aim:
To implement python Program to Check if a Number is Positive, Negative or 0 using if...elif...else
and nested if...else statement.
A.2 Prerequisite:
1. python basics and control structures
A.3 Outcome:
After successful completion of this experiment students will
be able to
Decision structures evaluate multiple expressions which produce TRUE or FALSE as outcome.
You need to determine which action to take and which statements to execute if outcome is TRUE
or FALSE otherwise.
1 if statements
2 if...else statements
You can use one if or else if statement inside another if or else if statement(s).
The if statement alone tells us that if a condition is true it will execute a block of
statements and if the condition is false it won’t. But what if we want to do
something else if the condition is false. Here comes the else statement. We can
use the else statement with if statement to execute a block of code when the
condition is false.
Syntax:
if (condition):
# Executes this block if
# condition is true
else:
# Executes this block if
# condition is false
A nested if is an if statement that is the target of another if statement. Nested if
statements means an if statement inside another if statement. Yes, Python
allows us to nest if statements within if statements. i.e, we can place an if
statement inside another if statement.
Syntax:
if (condition1):
# Executes when condition1 is true
if (condition2):
# Executes when condition2 is true
# if Block is end here
# if Block is end here
if-elif-else ladder
Here, a user can decide among multiple options. The if statements are executed
from the top down. As soon as one of the conditions controlling the if is true, the
statement associated with that if is executed, and the rest of the ladder is
bypassed. If none of the conditions is true, then the final else statement will be
executed.
Syntax:-
if (condition):
statement
elif (condition):
statement
.
.
else:
statement
PART B
(PART B : TO BE COMPLETED BY STUDENTS)
(Students must submit the soft copy as per following segments within two
hours of the practical. The soft copy must be uploaded on the Blackboard
or emailed to the concerned lab in charge faculties at the end of the
practical in case the there is no Black board access available)
Grade :
B.4 Conclusion:
(Students must write the conclusion as per the attainment of individual
outcome listed above and learning/observation noted in section B.3)
B.5 Question of Curiosity
1). Write a Python program to find those numbers which are
divisible by 7 and multiple of 5, between 2500 and 3600 (both
included)