Python Conditional Statements Guide
Python Conditional Statements Guide
3ve1mm,n~
f:i c.c.. - 3 o 2-
[Link] : &-Tech
&.cm~ : C... 5 2. E ~ tr
n
f [Link]')0n ._.,:i\fT~ t , , ,,:,~t "U <·.-.,,/wl (, .-.,..,~ '" t..-, pt•qt ·/t),, t
C.i;:"-f) b... t',,t 1.'."c1°"'f~ \t f"\ ' t""-" f"'\].,H" \.~ . t\foll1, ,1tfy , l•, ,,
1'0'1'\) -~or ~t'-~ bofh.'tl) , ti) •h,r '"", i~ ll) ""h'\'" lt,t-y ,,rr""n·
r""' ult~ w1't"r~ uu """'"''' J -lo C-'lt ('tu t~. tl .•!\.' t ~ (. fr\lff'rl"n,..
a "ho 1n e-Y ~ e.t- tj ~fd t e.m <U),,.. ~G ~ -+--o h(l. ~ --x e. tu.1 -e ~
1-
~ i..t c..c. (f ed d e. c.J.. .l: i ~ Co1'\ h-o/ -P-~ -$.1-t1 temer,t~ .
**
I~,
IT .STATEMe::1--JT
. _r
'T i.s a ~ ~;mpfe. tv)~t-hocl of c..h ~c.~ 7or
tondth ans · WhEU1 w-e. {fv-Q O c..cod,'h an of+e-r ➔ he. ~~w~J
\r-U"\'.~~cJ oT>d if ,1- ,·s; +rue i±
1
if' .-r-h~ c:..o-ndih'oY) is
e ')(_ e tut-e a -s= e..t- <t( .s.-16-f e.m ~r V) -th e. bo.1 'f 0 f if -
.Siotem ent ·
e
~~~ Flow [Link]"Tt
tloc.t. of
.St·d f-eme.l) t~
if e.)( r ~ ;OT):
..Si Cl 1 eml'J)1 1.
~ ~ For r1
q = Int ( ;'Y1Fu1- ( '' tJ1t er a ''))
;f a > 100 :
** TF ELS£ 01ATEMEN,S
Tf -the. co-ncf ,·hO'l') '4 !"Y'u e... 1 en e _g cu- of «. nd-.-1J t.h' e--n.s a "rt-
e."X... e.t..u:t ~ if ct
I .I.&. Fa kae. I O"noihe'r' ..se.J- of ._5;-fa-femef')t-
Fake.
&1oc.t- of Bio~ of
'"5tc,t~+z ..£+af-emer)ts.
)( }( )( ~ Y'">kl:><
if e~.c.c iefr) :
...Siq-f e.N')e.t) t- J..
cus.e..:
...S f··ed·ern er) ~ l.
~7< r~ . . ~ ®
"Y'\ u,.IY) ::.. - 1 O
'f e 1tf el~ e. -s:: +ate,n el),-: , m o '\-e --+nan oY) e Oo'n dJ. nem CA.O
k o..d.t.f,.......vcaJ U> ~ .
if ert!'~ionL:
~ement- 1.
eJif e-x~iOYl 1.:
I
-ri-ue..
Bio c.x of
So-fe,nel")tt. Ul\d~
e1...if
f>loc.t.._ of
.,___ _ _~ ~+at-em el') t:s ~ey
q, - loo ~
~I - Clo e,
71 - So c...
GI - ,o b
S-1 - Go E
<-= so F
p'OY'\t. ( 11£rrLcr 'Yn <lT b:. of .C.1 v <luff Ul ~ ~ ~ '° 'J n/sJ
''
'YY)(')T
ind
k.- 1 :;;..
i,rc·•t,, ~
( f) f t"Y' 'N I ut.
II )1'
')
to t ~ ':;.. h'>a-r t:- t + .mm t.-. ::i. t- mer,- t _3 + rrKTr ~ - "'- + ,,..~ t_ i:-
pn-n ,- (''A,,) I
ci.i-f Q >: SI ~ °"'1 < ~ ~o :
f'O"O r ( '' S')
€Ujf- ~ ";>:: 71 ~ 7 <:=- &o :
.
f1YYYlt- (c_')
~+ ~ > ::bl a.-"-4 ac:::.~,o:
•
• rn-rn t- ( ,, D 'j
I
Q <:: bO :
rue . 1
take.
~'fqf eme.t)t 3
Fal~e
~ * -Fer~
E.l+ WAP lJ) py!n~ -t-o e,iter a(je. and p-ri-,,t- if --lhe. •
X = ><+(,
,e.f,f O>~ .'
'){ = X +7
[Link]. ~
X-= x+g
[Link] :
)( :::.. X +4-
~,- (~)
6)
J:l€-r~CW"I 0.....- !oor ~,,.,., e.i lo g; f ua h
0
~~ Flow c..hort
Fa~Q.
..Sfatt!.IV'\C?.r) ,-
a~ ..... Loor
.s~[Link])~u
*4{~ _!,ynto.y.
whi u. ~~pTl9~ ion :
~ tat emcl) t L
i= 1 ..
p"rn"I t ( _P-nmncJ -nu.m b=...i: '1 +o '' , 'n)
wf-nk •<= h :
p-n~ t- ( i)
; = i +I
ie""f = "num
,ev:: o
W h1 l.J. num > o :
d,(j'~ : . ""l)um '/. ro
-yev :: ~v ~ 10 +cl
mum//= lo
if ~ -""'P c ::: oe" :
p-ymt- ( " [Link]~ :)f
el~e :
f"Yl r ( ')No,- pa..G YldYll -rfle. ")
Q WAP 70 ~cf fact-o-n·n.f of a nHtrh~r.
,iun,== ~
fac.J- = J.
whit... num >o ~
-n um :. "1um - I
Co [Link] t ":: 0
No re .. -!u.m 1 wi>~ °t ~ u
"Oum = I ~ 3
~ r c:; -[Link]
..Su.m- " o) = 0
W 1--n u. -n u..rn >0 ;
~t ~ ~LL-m /. ,o
~UM- vo..l =- ..St..u-n -Vo.I + d......rl ?f?t 3
'Y'\ u.m // = Io
if l ernp = =- ....s [Link]\- v ~ :
pnnl- ( ~ ~ J 'J
el.c..o :
F'"'1" (" Not; a-,y-,,shoj _:)
p-n-nt- ( 0 )
~p = a +-b
a -=- b
h =- ~.mp
[Link]\t-- c. Cou'lt +- I
*~ -Fo--,,- loop S f-o t,em e,,tl; {j)
-'t- u Q l.s.o -','m:la"r to w~lt. l«p [Link]<J ,·~ ~ x f.'(uJ-oj ~l,1ny
.Ji~.
~ ~ Flow UlCJYt;
[rit<"T\~
•fo,-, k,op
~tateroent- ~""
-fer ~ ~~ ~ - - - - . J
-~t-
,S'/NfAY
•
•
D/p
j_
+
l
*P -ro,-:ams om -{-o"r loC'I p
& , \NAP -lo ~~ '[Link] C'r~ r-fyurn /l:1 -to I ,
pm"' t ( i)
if i/. ~ = = 0 ~ ·, /. ~ :::. = 0 ;
[Link].
Rest- of
.__-____..~.+a t-e.m el"),-
tr, I
* )( .')( ~ =a .
+-r J in " fyih O'>) Pj-ra m rnia / .'
if L ~ =-.. 0
1
' :
r· 'r'\ t- (,) .
.'
r
,r ,, ,,
,n.~ p,,,<:. ..!! i <1 t , .. tnl•n t p,n <" ll <' "U'/ do r-.: ► H)l f1''"U nn,~
b chovr.( Ut: , tl (1,nv~n «''f) f • l',u. t , p ,1,!.t ~ lnk,nt1•f)~
'u ''nll l ·u no;,•d Ly t,rfr,,,-.-.,,..., / 1,-,(.,r :1
• 11 1(' -~ nnl"•l
~ ( s)·.
~
l.. NO OlfTPUT:>
~ ~ o - . : t ~ e,-d;'
* N~~ loop
loop [Link] arncr-fher loop ~ 1'.s c..atted n~~ foop •
* WAP +o jer,pyal-e ~e. [Link]) ou.l"pW ·
* 4-
"7) ':::. S"
"roe (in,
* ~
* 10V' i
** ~
~
~
**
~
*
~
... -ferj
l/)
Ul -r,r
=
(it I) !
*
~ ~
~
*
~..- (',.,,.,,, end - • ')
~ ~
P"'"" t- ( )
* ~ i (I) ~O'VljC.("1)~
-f-,- j in ~ e , ( i+I, h) :
prvn ~ ( ,, ~ ,, t Q/l d :. II ")
fil w~f -to p~t'" "Y"\l17"'1br-,-" tn ~)( ~ ·fo r,·f"YJ.i. ,
I) ~
,, S' (_.
., g '1
'[Link] .:;_ t
.r~J· V) "YU./\qe.. ( ~) :
pTmt ( [Link] , CJ")d ~ ,. '')
to un t :; w VI),. +- t
rn't { )
p-nnt { )
~ * ~
**-it~
-f',e-v- i l/l . ~ ( 1, t) :
~ J U'I ~ (L):
rn~.. ( .t ¥- ,, , encl :: • j
p,i,,t- ( )
1
f 'l-
11. a
j 2.. 3 4-
--fov- ...,-0 (
-ra (,
j U) I, !;) :
-fo-. j in i+r) :
p-n~... (j ' end :0 • ")
p-rmt-- ()
pn·n~ {)
&b wltf> +o prrr,r ~ ¼.A..L-tt) ~ nUft')b~ .
I I '
1 l- .2..
3 3 .3
for i in ~ ( ,, 4):
~ j U) ~ (3):
prn,t-( i , enc:I ::: ,,, "j
,mot () .
{x 7 · W llr · I o f"'n t· ct 0. p!\o. [Link]. { -..1 '"Qt.. ·
~
A-~
lr~ L
A-e c.. ~
..fo-< j U) o<: ( r) :
F"O t- c )
&~ NAP -to F',. hotrrJvv 4u.a-re ~ ·
• -X-
~
* ~ * ~
* ~
** **
Y) ~ s-
~ j l/). ~ (-n):
~ J
if
i.n
i -= 't:.
u.
o esr , -= = 'l1-r
('Y)):
err-
.
J =--=- o errJ =.. :. n-,:
p--o-n r ( ,, * 11
' [Link] e ,, ':)
e..l~e. ~ .
Fr(,, [Link] - ,, '')
p-n,nr ( )
fil ""AP +o r'""° t-
i
,. .3
+~ "
7 g '1 lo
C [Link] : 8 ,Tee ~ Bl-and) '. cs a ,T
Turo"I A L : 03
&i D--s (.tJ.S~ S y rda 'X o{ wl, i u. loop wHh ~imp:'2- ()¥ompla..
[Link] e. i.n python ,
-
Qg WhQI-- le -h~ [Link]:I ?
fov- X Lo ~~~ {1,q,3) :
prmt (x)
(t1) c ... o"r [Link] ,, ~, ~,+ , ~, e,, 7,g
Y~o:r / ..S @.m : 2.. nd/ ~-r4 -Su~ e d : Py1hon f'YOJY'ornm i'j
Sub c..ode : Bc.c.. • 3 O l.. Tu f o-nr,J No : 0 4-
~ f =- lo
ci-~ 4-
~ t ( p "> i and p < io)
Ft- ( ~t- ( P = = '°' c,y- CJ-==:! 4))
-:X. =~ 6H,
if 'X >0 : -..fov. ; i.n -r(l"t')jC. ( 3) :
pn-nt-- ( ~ Po1i h~ "')
if x.;1. '2.= =0 ~ rmt -( 111-tcLt.o 'j
p~, .. (~ ':) p-rhlt- ( ,,Wrnci j
t! l.s. e : rm~,- (' btrr\ e J
fM-r>t- ( • (SUq ")
,~ 11 '
-
Q.7 'X. = IO
y : JO
X = ,~
-
Qq
•f X/, a -= ::=-o a-nd --x/, ~ = =o:
p--n-nt- ( " b...v>'~!.U. by 3 O'rn.d s- ~)
-e.J if X/, 3 -== -=- o
prrnf-{ '' ~~; blL by 3 "')
els~~
,
-
~IO I == I
wmu.. i<. .t'":
p-rin t- ( ; * ,, *'~
' ,
r := I -t-1