Professional Documents
Culture Documents
Laldas
SE comps A
Roll No-53
Experiment No:- 04
Theory:
For each number divisible by three the computer will display the word “fizz”,
For each number divisible by five the computer will display the word “bizz”,
For each number divisible by three and by five the computer will display the word “fizz-bizz”,
We use for loop to itterate an range function to specify starting and ending number.
Flowchart:
Code:
for i in range(1,21):
print('Fizz BiZZ')
elif i%5==0:
print('bizz')
elif i%3==0:
print('fizz')
else:
print(i)
Output:
student@lab:~/Desktop/A53$ python3 range.py
fizz
bizz
fizz
fizz
bizz
11
fizz
13
14
Fizz BiZZ
16
b)A python program to display even number between m and n(m and n are taken from user).
Theory:
Here we ask the user to enter the starting and ending value,we print all the even numbers between the
mentioned range.
we use while loop for itteration and modulus operator and if control statement for calculating if the number is
even or not.
Flowchart:
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
Conclusion: Hence we successfully displayed even numbers between mentioned range using while loop and if
control statement.
c) Write a python program to swap two numbers and find whether the first number is positive,Negative
equal to zero.
Theory:
In this program we ask for 2 numbers from user and swap them,we then check if -
Flowchart:
Code:
x,y=y,x
print("After swaping")
print(x,y)
if x>0:
elif x<0:
else:
OUTPUT:
Enter 2 no 8 9
After swaping
98
Conclusion- Hence we successfully swapped 2 numbers and checked if the number is positive,negative or equal
to zero.
d) A python program to search for an element in the list of elements(The list must be entered through
keyboard).
Theory:
In this program we search for and element in the list,list is taken from the user.
we have used if control statement for comparision between key to be searched and elements of array.
we array element and key are equal we display "key found at location"
Flowchart:
Code:
c=0
for i in a :
if i==n:
c+=1
m=i-1
if c==0:
else:
OUTPUT:-
enter a list 2 5 6 7 8 9
Conclusion:
Hence we successfully implemented the program using for loop and if control statement.