You are on page 1of 4

2/2/23, 4:32 PM BA8-Notebook - Jupyter Notebook

Q. Write a program to find those numbers which are divisible by 7 and multiple of 5, between 1500 and 2700
(both included).

In [2]:

n = int(input("Input a number"))
if (n%7==0) and (n%5==0) and (n>=1500) and (n<=2700):
print("divisable by 5 and 7 and in between 1500 and 2700")
else:
print("not divisable by 5 and 7 or in between 1500 and 2700")

Input a number35

not divisable by 5 and 7 or in between 1500 and 2700

In [4]:

n = int(input("Input a number"))
if (n%7==0) and (n%5==0) and (n in range(1500,2700)):
print("divisable by 5 and 7 and in between 1500 and 2700")
else:
print("not divisable by 5 and 7 or in between 1500 and 2700")

Out[4]:

True

Loop:
It is used to repeat a particular operation(s) several times until a specific condition is met.
It is mainly used to automate repetitive tasks.

Real World Examples of Loop

Software of the ATM machine is in a loop to process transaction after transaction until you acknowledge
that you have no more to do.
Software program in a mobile device allows user to unlock the mobile with 5 password attempts. After that
it resets mobile device.

1. While Loop (indefinite iteration)


2. For Loop (definite iteration)

In [ ]:

1.While Loop:

while expression:

statement(body)

localhost:8888/notebooks/Term4S/scripts/2A/BA8-Notebook.ipynb# 1/4
2/2/23, 4:32 PM BA8-Notebook - Jupyter Notebook

In [8]:

n = 1 #intialization
while n <= 5: #termination condition
print(n)
n = n + 1 #increment

localhost:8888/notebooks/Term4S/scripts/2A/BA8-Notebook.ipynb# 2/4
2/2/23, 4:32 PM BA8-Notebook - Jupyter Notebook

In [9]:

n = 5 #intialization
while n <= 10: #termination condition
print(n)
n = n + 1 #increment

10

In [10]:

n = 1 #intialization
while n <= 10: #termination condition
print(n)
n = n + 2 #increment

In [13]:

n = 1 #intialization
sum = 0
while n <= 10: #termination condition
sum = sum + n
n = n + 1 #increment
print('sum ',sum)

sum 55

In [14]:

n = 1 #intialization
sum = 0
while n <= 10: #termination condition
sum = sum + n
n = n + 1 #increment
print('sum ',sum)

sum 1

sum 3

sum 6

sum 10

sum 15

sum 21

sum 28

sum 36

sum 45

sum 55

localhost:8888/notebooks/Term4S/scripts/2A/BA8-Notebook.ipynb# 3/4
2/2/23, 4:32 PM BA8-Notebook - Jupyter Notebook

localhost:8888/notebooks/Term4S/scripts/2A/BA8-Notebook.ipynb# 4/4

You might also like