MAY,27,2026
HI....
Train Story:
TWO TRAIN ARE THERE TRAIN ONE AND TRAIN TWO.....
TOTAL STATION:(1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30)
TRAIN ONE=T1
TRAIN TWO=T2
T1 T2
3 5
6 10
9 15
12 20
15 25
18 30
21
24
27
30
PROGRAM:
station_no = 1
while station_no<=30:
if station_no%3 == 0 and station_no%5 == 0:
print(station_no)
station_no = station_no + 1
WHILE USE BREAK WHAT HAPPEN:
station_no = 1
while station_no<=300:
if station_no%3 == 0 and station_no%5 == 0:
print(station_no)
break
station_no = station_no + 1
break --> breaks the loop
The break statement in Python is used to exit or "break" out of a loop (either for or while loop) prematurely, before the loop has iterated through all its items or reached its condition. When the break statement is executed, the program immediately exits the loop, and the control moves to the next line of code after the loop.
A break in Python is a keyword that lets you exit a loop immediately, stopping further iterations.
A break in Python is a keyword that lets you exit a loop immediately, stopping further iterations.
Using break outside of loops doesn’t make sense because it’s specifically designed to exit loops early.
The break doesn’t exit all loops, only the innermost loop that contains it.
Reference:
https://www.geeksforgeeks.org/python/python-break-statement/
https://realpython.com/python-break/
NOW THERE ARE 100 STATION:
station_no = 100
while True: #Total no. of stations unknown
if station_no%18 == 0 and station_no%62 == 0:
print(station_no)
break
station_no = station_no + 1
station_no = 1
while True: #Total no. of stations unknown
if station_no%18 == 0 and station_no%62 == 0:
print(station_no)
break
station_no = station_no + 1
558 is a multiple of 18 and 62.
558 is the least(first) multiple of 18 and 62.
558 is the Least Common Multiple of 18 and 62.
Compilation
Interpretation
Police Thief
0 40
5 42
10 44
15 46
20 48
25 50
30 52
35 54
40 56
45 58
50 60
55 62
60 64
65 66
Police and Theif story solution
police = 0
thief = 40
while True:
police = police + 5
thief = thief + 2
if police>=thief:
print(police)
break
Task 1:
%3 ==0: --> Train One
%5 ==0: --> Train Two
%3==0 and %5==0: --> Both the trains
Task 2:
station_no = 1
while station_no<=300:
if station_no%3 == 0 and station_no%8 == 0:
print(station_no)
break
station_no = station_no + 1
Top comments (0)