

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These notes will help you to understand how to use conditions in Python.
Typology: Lecture notes
1 / 25
This page cannot be seen from the preview
Don't miss anything!


















elasSmAte
Page
CONDITIONAL
AND
IERATVE
STATE
MENTS
Generallyaprogton
execes
Hs Stade
ments
Ho end AlAhe progsansS cannotbe writeninSamepodtetn.
To pedor heirmanipulozivemifaclesorogramneedsbols.
heprogfem needsdoals dor pertosninqepeatadiveactian
candldhona
decisionnaking
lo
reuirementsPthonfrovidestolswhich areknawnas
Oroscm Cotrolstatements.
verProarainglanguagesuppacdsthsee_controlsttuctures
ADSeguendtial
Conddional
Selection
3
erdion
Looping
Statement Elow Coitrol
n
sequeho execdedether
Seqendially
Or
conchfion.ally
derativel,
Sequence
(he sequence
conSfruei
means the Stalemeds oue being.
execuhed
Sequenhially
e dehault
shode
ment i.e.
Haw ot
in a plo fam.
Stade mend Aollo ws he
Stcdernent
1
Stademert
n
Storemext 3
elasSMAte
Date
Page
selectionConstructmeans heexecutionot stotements
dependingupan
a
conditiontest.a_conditionevclucdesb
Hrueo course
ot
achanistollowedathetwise anctherccurseci
actionistallowed.This pMAraminqconstuciisalsokoown 4
dedsianconsttuctasithelpsinmakingdecisionaloaut
whidh setot stotementsarenbe executed
1s
Condithon?
LSet ot stadenm.ent/ Setor
studenueutcs)
3Herotionor
Looping
he terccion
atstotenmeats
dependinganc Codithondest.illthehoneaCanditianis
troetrve
shdements ore repeahed
again
QS Saam as a Condition becaes tals.ehe
and dheconmol is tronskarced
the
elasSmAte
Date
Page
statement..
a
a
b
inpuCEntec Aame?)
prind(Hello)
CompaundStade naent
A
compound
ment reptesents aroupof stadements
executedasunitA compaund statemen endswth calun,
underwhich multiple
ba
Stetemen Header
Statement
Stcdement
3 Empty Statermen
lhesimpleststodema iscalledtheenmpty stdemeht,it.a
stodementwkichdoesnathingwhichalsameans itreptesents
nullopercdian.Hcanbeplementedbycihingpass.
Tools
Behormdevelopin8acomputer progrannorogivesolution
ot
problem in
oproeramhe
analusedhe given pralalemarddecidealoutbasicsulataks
neaded tosclvedhe prolulenandotderottheseSu-rtasks
There sevatiousprayrologiedeveloamen nals,Someo
ase-
Agorithm-
An algorth
s astep-lay-
Step
osoluehe
problem tisaSetototdered ond Hriteshepsasalethe
elasSMAte
Date
Page
8ren
proble.m.
ram
algarithm
there
Iik.e
co
de,Howcharh,
decisionree..
flowchart
isagraphicareptesent.ationo anadgorithm.tA
shows d:lerentsub-tasksth dilerentsumbls.
Start/ End
Inputl
Output
Statement
Diamancd
2
Sulbtasks
flo
program
QDrawa How chor toindoutoreo otcircleAsowrite
Hhe
ses
Hawchcs
1Start
nput
radivs
3
radiusxT
4
A-3.1A159rr
End
pint A
End
elasSmAte
Date
Page
3)Pseudo
His
an
intocma
way
ot
olescribing
ota
profam's
Salutionwithout
using any Srictprogfaming
gug ntax
ar
undeclyingtechnaloa
considerodian.
Eg-
Ficst
input
anno.
adculate
areaas nos.Squae mutipliedb Pi
ib
nput
marks ina
sulaj.ech
morkS Qre more
than 33,
then
displo passed'L
else
display
hiled
Decision Tree
Decisian keeae ways ot presening-
rulesin
sequentia sttuchurewhere loasedon hiemrchyo tole
26ol lou
got distinction
Percentage
250 You a
tirst
Petcentage
31
ou
got second class
You
sailec |ou
gad
pa8sing maksI
elasSMAtee
Date
Page
in
Phon
Ihe
itstademeni is a
cattolled
shucture whichckecks the
condition
setot stete mets uhich sedisiesthe
lhere
voriaus
Alavour ot i-
f
else
A)Nestecdit
Fythonuppertsdeshingotcoalitianswiththe luelpo itecmtae
Simplei
stademerds anlyitthe conditionis
ue
Write a Pidhoncosle nieh iyoutsa nuher andcheck wether itis
positiveo1not
int linputEniera no.-
nzoi
print(Na
is
posihve?)
2Q nputa hauberand checkhethesisdwadiitpositive
Mwmber
n intCinput
C Enter
a ns2)
n79and
priatdlaiswo diatpostiveaa)
3QWrde aPihanCade uichinpuisa Jaialaerwheikertis2add
or
noi._
AQwridea
Pdhon
cale
inputs
maksata studentina
Sulajec check
shudet passeaornai Ssumin
mcx matks
00
elasSMAte
Date
Page
QWrde aPyihonccde whichinputstemperatureotalercheck
shetherihas
or_net.
nE int(input(Eterdemperahure2)
nE=iO
print(Waterhasrechedbailingrheactingpoin?)
S.Wrhe a Pthancode aishiapuisprincipleohaltimedd
diapleintesestprincipleamauutis
haore
fhan
2500o,herateo inderestis.
2 :intLinpuiEntertioie22)
Q5606naiulinput(Enterprinciple)
Gs p=nt 25000
G.S
Sipxr
t
100
(si)
p-
(Enler
principle
L:intinputEnter
time)
_p
25000_
6i
p r&t100o
(si)
2Q.nput
a chocacter
ohetheritisvowel
orhal
n:
acharacter)
i n:a,e,,0, 1
ifn-a?or ne or nio ne'oor nw
printCharacter
is
a vowel')
elasSMAte
Date
Page
2
elsestatengent
lhisdotrm oit_stotemenmHestsa condiitionanditthe
CAnolitioneveluates o trueitcarriesout stodtements
it
And the condtionevaucdesto Jalseit carriesout
stare mets
irdenteolbelow
else
condiion)
set
stadementcs)
else
set ot
stotementCs)
n: int
Entera no2)
in°/o2=
printNoisEven")
else:
printnoisddd?)
Write a
dime
more
than 2000o theateor ideres
pplicahle
lapplicalule iso. cherwise 4 CalculodctheSimple interei
pE intCinputEvter principle amount))
t intCinput(Ené ine')
i
p200oo:
Si
pkrxt/AoO
Csi)
alassMAte
Date
Page
C
is a
else
ptind
1
aconsonen)
Qnputage o apersch.Chechdhe pese iseligblevater
age npehEterageintlinputCEnterage?))
itage
=
print(Personiseliibletovote)
else
vote)
Emer a
year hech whethes itis
nat
int
Chnpu
in tebruary
Macth)
year:int Cinput Enterayear )
year
4==0:
printHs
aXeapyenr")
else
printlHs
nota
leap
ear)
OWridea
codewhich
inputs salaryot a Sales person and
sales
out
he
total
Selaryo asales person he
hos Made salesQove Ks
qetsa
e.mmissian
io"/else
Commission
is27aothe sales maol
Salary
in
CinputCEitersalary»
2
iSales>
CESoles
else
CE
Soles
elassMAtee
Date
Page.
tata
CtSalary
printTata
is,selee total)
Qnput dour number. Findlasgesh amonj1hem.
a
Cinpu Enter Ast na.
b:intCinputEnter 2nd no.)
Eintinput Enter3rdno.'
deintCinputEnterthna.
i
azb:
else
od
else
L:L
else
LEl2-
printLargest
na.
is,1)
put dnnuaers,dhe stnunmoer slargerAhanseco nunber
hen wap
the bath
nunnoess atherwise
psintculae
o the Smaller
2Q
Enter
istno.
b ntCihput(Enter2d ao)
iazo:
elassmate
Date
Page
printH's_an acute angle)
elit
anle 90
print(Rsan olatuse
elit angle
90
printf's aright
Write a Pdhon code whichinputs hreene.Eid lesgestamang
Hhe
a int(input(Enteristno.2»
b:intlinputEnter2ndno.
cEintlinput('Enter3rdna)
iab and azc
print(a,islargest)
elit b2a and o>c
pcint(b,is
largesi)
else
prid(islarqest)
Qhputamorth na.leitea pyhoncodewhichprintscoLespanding
ncme and
itcorntains.
mzintCinput(Entec
nonthno.
im=
printIts
31 days')
elf
m=-
prinlHs
with
28 days)
elmE=
3
printCls
Marchwth
31 das)
elitelit
m==
print(ltsAprilwth 30 days
elitm 5
peint.CHsMaywith 3 days)
elassMAte
Date
Page
elit== 6
print(HsJunewth 30 daus)
eli
==
printHs duly
31 days)
eli-
prittsAsustwth 31 days)
eli
orintCItsSeptemlaer
wth
30 days)
A
print('HsOcdober with 31 days)
eli==
printtsNovémber wth 30 days')
-=
print(hsDecember with 31 day)
noprint
name
d int
da na))
d=
ptinttsMonday
eli
d==
printHsTuesday
elif d=
prins
elif d= 4
priTs
elit
de=
printHs Eriday
lelit d=o
Sturdoy)
elit d
printCHs Sunda
lassate
Dete
Page
tchsiaor ch'eorchs ch zdor chz= o he-a
ch:crcha:1o ch= 0 a cha:V
print(isa voel)
elich>:B and ch 2ach2:L and chk: _
priCHisoconsanant)
lelifcho and dhx-o
primCisa
elce
prim H iso special
QWi ea Puthon code
whichinputs
number otcalls
custae
usinghe servicesc
CCmpany heLtol Lillx
o nondih
celculated os
tollatwing slab
Numbe o Cells
Rte
Upto 100
01 to 3oo
O
301 o 550
55 o A
5O050/callin exess o
exsess 300 cals
excess d 551cals
AO
200t125lcallinexcessc 000 ccls
Renta phone chceges isBs 8o dorall costomer
no
intinpulCEnler
ngeo
calls)
it
E
ail 0
classmate
Date
Page.
eli noci00and
noc
300
bill= 50+0SO* Cnot-1O0)
elil
noc an ns K: 550
15+075*noc300)
elit noc2550ánd noc IO
laill150+1*no551)ON2A
else
bill:200+12SK noc - 1O00)
b: ill
80 hetoll
(h)
Qnputbasicsalaryoian eraployae Calcukdetheaoss salary
Sasic Salas
DA HRA PE
3:
28
S2/
43
501-b
125
AR
13
bsE itCinput EnteroasicSolary
pasicsbs+bs28/460+lasoo0bs-4.5toe
hs=oSo
asks:losbs28/10o)Hlas2/1o-osA26/1doaa