You are on page 1of 6

1 Python Experiment NO 07

FS20CO047
Experiment 7

Shrikrushna Dilip Patil


8th November, 2021
2 Python Experiment NO 07

Title:
Write a program to demonstrate the use of if and if else

Theory:
1. if statement
An if statement consists of a boolean expression followed by one or
more statements.

2. if else statement
An if statement can be followed by an optional else statement , which
executes when the boolean expression is false .

3.if elif else statement (nested if statement)


You can use one if elif else statements as nested if statements in other
programming languages.

Break statement:
The break statement is used to break out of a loop. It is used inside for and
while loops to alter the normal behaviour. break will end the loop it is in and
control flows to the statement immediately below the loop.

Syntax:
for i in range(1, 11):
if i == 7:
break
print(i)
print("Loop terminated")
3 Python Experiment NO 07

Continue statement:
The continue keyword is used to end the current iteration in a for
loop or a while loop, and continues to the next iteration. The
continue statement is used to skip the rest of the code inside a loop
for the current iteration only. Loop does not terminate but
continues on with the next iteration.

Syntax:
for i in range(1, 11):
if i == 7:
continue
print(i)

Return statement:
The return statement is used inside a function to exit it and return a
value. If you won't return a value explicitly, None is returned
automatically in Python.

Syntax:
def funtion_name():
statements
.
.
.
return [expression]
4 Python Experiment NO 07

Pass statement:
The pass statement is a null operation; nothing happens when it
executes. The pass is also useful in places where your code will
eventually go, but has not been written yet.

Syntax:
def func1(args):
pass
class Person:
pass
print("Successfully Executed")

Practical:
a. Check given Number is odd or even.
Program:-

b.Display grade of student depending on percentage.


Percentage>==90: Excellent
Percentage>80=80 and <90: First class
Percentage>60=60 and <80: Second class
5 Python Experiment NO 07

Percentage>=40=40 and <60: Pass Class


Percentage<40: Fail
Program:-

Observation:
a.
Output:-

b.
Output:-
6 Python Experiment NO 07

Conclusion:
In the above programs I have learnt the use of if else statements .
It helps to give the conditions in the program.

You might also like