Neel Sanjay Bhatt Roll No:-07 Div:A
Neel Sanjay Bhatt Roll No:-07 Div:A
Neel Sanjay Bhatt Roll No:-07 Div:A
Roll No:-07
Div:A
EXPERIMENT NO:4
AIM: Write a program to demonstrate use of control statements in python:
A. IF-ELIF-ELSE STATEMENT
The if-elif-else statement is used to check multiple conditions.There can be multiple elif test
conditions.
B.WHILE LOOP
The while loop is used for executing a block of code multiple times until a certain condition remains
true.Since the loop needs to terminate so the iteration or terminating statement is written inside the
body.
C.FOR LOOP
The for loop is similar to the while loop except that the for loop uses a sequence for the execution.
FIG:FO
R LOOP EXECUTION
a)Write a program in python to implement FizzBuzz
Code:
for i in range(1,21):
if i%3==0 and i%5==0:
print("FizzBuzz")
elif i%3==0:
print("Fizz")
elif i%5==0:
print("Buzz")
else:
print(i)
Output:
lab@lab:~/Desktop/A07$ python3 ppy.py
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
lab@lab:~/Desktop/A53$
b)A python program to display even number between m and n(m and n are taken from
user).
Code:
count=0
while range(x,y):
if x%2==0:
print(x)
count+=1
x+=1
print(count)
Output:-
20
22
24
26
28
Total count is
5
c)Write a python program to swap two numbers and find whether the first number is
positive or negative or zero
Code:
x,y=y,x
print(x,y)
if x>0:
elif x<0:
else:
Output:
lab@lab:~/Desktop/A07$ python3 swap.py
Enter 2 no -3 4
After swaping:
4 -3
1st Number is Positive
d)A python program to search for an element in the list of elements(The list must be
entered
through keyboard)
Code: