You are on page 1of 1

Py

thonPr
ogr
ammi
ngExer
cises
Ar
ray
s
1.Thedai l
ymaxi mum temper at
ur erecordedin10ci ti
esduringthemont hofMar ch
(all31days)hav ebeent abulatedint heform ofanar rayinwhi chthef ir
strow
denotesthet emperatur
erecor dedatthe10ci ti
esonMar ch1,thesecondr owf or
Mar ch2,andsoon.Wr i
teapr ogram t oreadt hetableelement sintoat wo-
dimensionalarraytemperatur
e,andt ofindthecityanddaycor respondingtothe
(a) the highest temperatur
e and ( b) the lowest temper atur
e.[ Hint:Use
dicti
onari
estodi spl
aythenamesoft heci t
iesi
nt heresul
t].

2.Thef
oll
owi
ngsetofnumber
sispopul
arl
yknownasPascal

str
iangl
e.
1
11
12 1
13 3 1
14 6 4 1
1 5 10 105 1
…………
Ifwedenot er owsbyiandcol umnbyj ,thenanyelement(
excepttheboundary
element s)inthet riangleisgi
venby
Pi,
j=P i
-1,
j1+P
- i
-1,j
Wr it
eapr ogram ( usingarray
)tocal
cul
atetheelement
softhePascalt
riangl
efor10
rowsandpr i
ntt her esul
ts.

3.Youareaskedtopr ogram anairl


i
nereservationsystem.Youaretowr i
teaprogr
am
toassignseatsoneachf l
ightoftheai
rli
ne’sonl yplane(capaci
ty:10seat
s).Your
program askf
ortheper son’snameshoulddi splaythefol
lowi
ngmenu:
Pleasetype1for“fi
rstclass”
Pleasetype2for“economy ”

Iftheper sont ypes1,t heny ourpr ogr


am shouldassi gnaseati nthef i
rstclass
section(seats1- 5)
.Iftheper sont y
pes2, t
heny ourprogram shouldassi
gnaseati n
theeconomysect i
on( seats6-10).(I
faseati sunavail
able,menti
onsoandgot ot he
endoft hepr ogram) .Yourpr ogram shouldthenpr i
ntaboar di
ngpasst hatincludes
thenameoft heper son,theseatnumber ,andt het ypeofseat.Useanar r
ayt o
representtheseat i
ngchar toft heplane.I
niti
ali
zeallt
heel ementsofthearrayto0t o
i
ndicatet hatallseat sareempt y.Aseachseati sassi gned,setthecorresponding
elementt o1toi ndicatethattheseati snolongeravail
able.

Attheendoft
hepr
ogr
am,
youmustaskwhet
hert
heuserwoul
dli
ket
obookanot
her
ti
cket
.

-
--
--
--
--
--
-

You might also like