Unit 2 Python Operators and Control Flow Statements Part2
Unit 2 Python Operators and Control Flow Statements Part2
O/p
fnter3 numbers
15
25
35
35is larqest
1Looping in Python
loopinqtatemen tS care to execute
block
Ihe
of Statement.Sepeabeelly for severatimes
while loap
for loap
1The while loop
Same that
Python'S while loop 1S eractl as
in Jay4
we usedn an d C C t t .
The only Suntax is chanqed
- Syntaz
initialization
whilecondition
Statement-1
Statem ent-2-
Statement-pL
increment/decrement
willepeat
After nitializinq, the while oop
condition vem ans
its iteroations until Specified
every iteratOn it will per form
Irueand oO
9pecified increment decyement.
increment operator
-Python does not Support
t ) a n d decremen E operator =
to pTint"Hello all"
Python progrGrm
messaqe l o timeg.
i-1
while iK : 10:
print (Hello all)
:it1
the uSer
a
value: "2
pint("Enter
num int(input ())
Sum O
while iK:num
Sum:Sum t
ii+1
print(Sum i9:, Sum
o/p
Enter a value:10
Sum iS55
Statem ent - n
fallawinq progYam wheze weinclude rangec
Pram to Lo:
func tion t o prIDt alL the numberS
print ("manarea 8tarts")
far i in 1anqe(i,11):
printCi)
a r e a ends")
print ( majn
Start Writing From Here
3 Neste d LoopS
-Python also allows to us the cancepb et
nestedloops, where we use one loop inside
anotheer loop
The very
-Ihe veny- famoug_ patternproqrams and
man
ather Situations ta use ne sted loopg.
Pythonprogram to print fottowing pattern'
3 keyword pass"
"
else"
4 Key word
while 1K:5
printSEaIt'1
fi-3:
bresk
print ( End" i)
ii+
O/p
Start
End
End:2
el$e
print("Current Letter:", letter)
0/P
Current Letter:P_
CuTrent Letter Y-
Current Letter: t
Currenb Letter , O
Current LetteY,n
00P Manipwation usinq keyword "else "
nPython , a loop_Stctemen tg may have
o nelse clauge l t S e1ecuted hen he
100p ter munat e 8 throuah exhaus tign of iStt
-or when the condition esult9 false
Ciowhile- loop)
Pythan program
whlei :5 :
Punt C)
i2i+1
elSe
pint ("1oop ended ")_
O/P
5
loop ended