Professional Documents
Culture Documents
d G . m mg
an etting Start d
with Python e
~ ; Introduction
~ , computational Thinking 5.5 Working in Python
:, .
_, python - Pluses 5.6 Understanding First Program/Script
: .)
, ~ python - Some Minuses
,.1 INTRODUCTIO N
96
COMPUTATIONAL THINKING tr rs can be used for sol ving a varieh,
5.2 ··· · dcni age cornpu ·.-1 b f 'J
·ts power and capab1lihes, mo . lex ones. however, e ore a problem
Because o f 1 • pie or comp d b
. blems from diverse .:ircas, whether ~101 . I . t ·t cou ld be sol ved nee to e understood
o f p1 0 . ) , s tnW1ICJ11 ·
an be tackled, the problem it-srlf and t lt wny. . , solu tion ~ 'iiffi-n6~,_ I
c . . . . f d ) solving or compu Ling a . MIL.U.41 !..'\L.!-4-
\!Vhen thmkmg 15 ocu~ _tn • . t ti mJI thinking. com putational Thinking refers t
for a specific problem, it is the Ct'lmpu ii c • . blcms the collect ive thought proce
0
tational thinking is an .:ipproad1 to solv1n? pro "nd involved in formulating probt:ses
ComPu . l sc,encl', o ms
. ,.,
usmg conceptS an 1 b , d 'd ~;1s from co111 pu er ·
be run
and solution s so that thl)\,
d ~, are
. . t1 , . . oblcms so tha l t1icy C011 represen te In a form th at can b
expressing solutions to 10~L pr effectively carried out e
~ a
on a compu te r. . . ss th at computer.
. . .0 bl m-solvmg pi oce
Computational TI1inkmg 15 a P~ . c ----
includes the following charactenshcs. problem, d a ta o r proce&s in to sm JJ
. ak ' down a comp 1ex a er
¢'> Decomposition. It IS tl1e bre mg ,
more m.anageable parts. . It efers to looking for similarities, patt, ,
·t· n/Data Representation. r t:rr.,
¢'> Pattern recogru 10
and trends in data. . . essary details/ information to focu s only on th '
¢ Abstraction. It is the filtenng out unnec e
important Information.. . . . tl1e common or shared characteristics. Somefunes
■ Generalisation. It 1s identifying .
Generalisation is considered as a part of abstraction. .
. , th d • g step-by-step instructions to solve this problem, or other5
¢ Algonthms. It IS e eve1opm
like it.
ti ·s devised it must be evaluated fo r ib:
Based on above characteristics, when a so1u on I '
effectiveness. Let us now talk about these characteristics one by one.
, De.::cnioos • O'"'
Decomposition is the process of breaking down a big or
complex problem into a set of smaller sub-processes to allow The process of breaking down a big
us to describe, understand, or execute the problem better. or complex problem into a set of
smaller sub-processes in order to
Decomposition involves :
understand a problem or situation
¢/ Dividing a task into a sequence of subtasks bette r, is know n as decomposition.
¢/ Identifying elements or parts of a complex system
I
or patterns among and within small,
¢) iden tify ing sim ilar ities or com ma decomposed problems; the
d .. identified patterns help solve more
us to sho rtcu ts. n ifferences that lead comp lex problems more efficiently .
¢) usin g iden tifie d sho rtcu ts,
the patt erns are iden tifi d tlmap ping problem charact . f1
once e , 1ey can be re r en s cs to poss1'ble solu tion
.
.
e exa mples of patt ern recognition.
5001 P esented through appropriate data . Conside
r
❖ Everyday exa mpl e. Wh ile driv ing
on r d . .
So the driv ers look for patt ern s in tra~~
s, swit~hmg lane s prom ptly may cause acci
. dents.
... Aca dem1c exa mp 1e. p atte rn reco gni't c to decide whe ther and when to swi tch lane s .
• · eous i·o · .
1gn , met amo rphi ·c , O r se d'ime ntar y. n 1s reqm red w h en ca tego nzm · · g roe k
s as e1t· her
:. Scie nce /Re sear ch exa mp le Scie nf
• . t d .
theories an d mo d e ls, e.g., · is s an eng mee rs look for patt erns in data to deri ,·e
■ Scientists disc ove red that the p t
. e als of fl owers, flower pisti· ·ls (see
ds arrangements m · the
centre of flower), pmecones etc. grow in
the order of Fibonacci series. Fibonacci serie
series in whi ch ev~ry next number is sum s is a
of previous two numbers, e.g., with first
numbers 0, 1, the Fibonacci series is : O 1 2
1 2 3 5 8 13 21 34 55 ...
■ In 1844, Nitr ous Oxide gas used by
dentists was considered a party drug, sinc
people 'hap py' and relaxed. A friend of Am e it mad e
erican dentist Horace Wells, took too much
the laug hing gas dur ing a stage show, hop of
ing to entertain the crowd. Dur ing the act,
acci dentally cut his leg, but to his surprise, he
he didn't feel a thing! Horace Wel l noticed
pattern of nitrous-oxide-and-feeling-of-no-p the
ain. Excited by this discovery, Ho race Wel
pate nted the use of Nitrous Oxide as the ls
most primitive anaesthetic.
3. Abstraction
Abstraction or Dat a abst ract ion refe
rs to focussing on Abstraction or Data abstraction
information rele van t to a con text /pro blem
and sup pres sing refers to focussing on informat ion \
other details. Abs trac tion invo lves : relevant to a context/ prob lem and \
¢) Rec ognisin g the con text suppressing othe r details. _
¢) Iden tify ing the info rma tion rele
van t to the context
For example, a dog ' s deta iled info rma tion
may include its colour, bree d, size , height,
shape of its tail, skip patt erns , dise ases, weight,
if any and so on
Ad raw mg · t h doe s not nee d details like bree
eac er d, weight, diseases etc. He just nee ds to
focu ·
s on col our , size, tai'l shap e skin patt .
erns etc. as h1s . • d f hi
- , context is draw ing an or s
· h
ab stra ctio n, t e d e t a1·is like bree d, wei ght diseases etc. are unnecessary.
,
.
A vete rina ry doc tor wi·11 h O wev er focus on details like breed, weight, diseases etc. as these
. .
are imp orta nt d etai·1s fo r his context and other details are unnecessary for h.im.
98
re port . ,, t.' :-um nhlrt Lt' ,Hhi d b , u ,.., nnl\ lhl'
❖ Acad em ic exam pl e. \\"he n we writ e .1 b1J,.1~
tr,h .·th'Hl.
them e or key aspe cts of the boo~ tt is ~t, -. 1 1 1ur ,, pl,1
engi nL'l' rtll~ "l1 lul m in ' prop n ... ,
11 11
ing exa m p le. \\'he n ,n.. O\ i'n it'\'' ,,n
•:• Engi neer
tlw d,•t.1it ... .
,,·e high ligh t the unde rlyin g appr o.-ic h .rnd h1d1.•
rJm t''nh -.h1.m ~ tlw nu mb1.·r, ,lll d )f'l' 1,1t11r
1 .,
❖ Com pute r S cien ce e xam pl e. A l°\lkulat\1r prng
l:-: l'I .,lglH 1thm pn,g r.im h.h•rn1..•lll h
11 1
func tion butt ons to u~er with out ginn g dl't,1i
!. Gen e ra zc•ro n
or shar ed d 1.:ir.K tl' ris tic~ bl'IWL'l'n two dom J
1nc, 0
Gen erali satio n refer s to iden tifyi ng com nwn r
cou ld be ,1dap t ed or app lit-J lo thl' oth er.
prob lems such that mod els or -~ol~ tion~ L1t one
Con side r follo ,\ing e\.am ples .
¢) When we cook, we taste our dishes and then adjust fl avou ri ng accordingl y.
¢) When we carry out a physics experiment, say, to find the relationship between
temperature and pressure, we check our data, investigate why it does not match the
theory, redo our experimental setup, and recollect data points.
1. Easy to Use
Python is compact and very easy to use object oriented language with_very simple syntax rules.
It is a very high level language and thus very-very programmer-friendly.
2 Expressive Langua ge
Python's expressiveness means it is more capable to ex_pressing the ~ode' s purpose than many
other languages. Reason being - fewer lines of code, simpler syntax.
For example, consider following two sets of codes :
; ; Inc++ : Swap Values ·# In Python : Swap values
int a = 2, b = 3, tmp ; a, b = 2, 3
tmp =a; a, b = b , a
a= b;
b = tmp;
3. Interpreted Lang uag e 'led language. This means that the Python
. d lan age, not a compi .
gu
Python is an mterprete nd executes h de line by line at a time. It makes Python an
. . . t e co
installation mterprets a ·t ble for beginners to advanced u sers.
easy-to-debug language and thus sm a
COMPUTER SCIENCE WITH PYTH ON YI
100
4 · Its Completeness
.
V\fhen you install Python, you get cvcr
ylhm g you need to d o rea I wor k. .You do not need t
L
:tm"ri1l~ad and install addi ti onn l librorics ; nil . l' . .
type s of required fun chd~na ityfuis a:a11able
°
•
through vano us mod ules l)f Pyth on stnn do
rd hbrary 1. For exam pie for 1verse nctionality
•
As per Febru ary 2013 popul arity index, Pytho n was 4th
most popu lar progr ammi ng langu age 3 after - Java, PHP
and C#. That is the reaso n, it's part of your syllabus. Python is an interpreteo ,a, g~c: g'::
Toget her w e'll make it playf ul Pytho n ;). th at is, all the comma'1d5 -you \ • ' : e
are interpr eted and e-<ecutec o,e
by one.
5.5 WORKIN G IN PYTHON
Before you start work ing in Pytho n, you need to install Pytho
n on your comp uters. There are
multi ple Pytho n distri butio ns availa ble today .
~) Defau lt instal lation availa ble from www .pytho n.org is
called CPython installation and
come s w ith Python interpreter, Python IDLE (Python GUI) and
Pip (package i11stal/~r).
¢) There are many other Pytho n distri bution s availa
ble these days. Anaconda Python
distribution is one such highl y recom mend ed distri bution
that come s prelo aded ,,ith
many packa ges and librar ies (e.g ., NumP y, SciPy, Panda librar
ies etc.).
~ Many popu lar IDEs are also availa ble e.g.,
Spyde r IDE, PyCh arm IDE etc. Of th6L\
Spyd er IDE is alread y availa ble as a part of Anaco nda Pytho
n distrib u tion.
To install any of these distri butio ns, PLEASE REFER TO APPE
NDIX A. We shall karn tu work
with both these d istrib ution types [but my perso nal favou rite
is A11nrn11rla ;) - not tlw rt>ptil t:> , th e
Pytho n d istrib u tion :))
Once you have Pytho n installed on your comp uters, you are
ready to work on it. You c,m "''ork
in Pytho n in follow ing different w ays :
(i) in Interactive mod e (also called J111111 ediatc Mode) (ii) in Script mode
Python 3.6
,. IDLE(Python 3.6 32-bit)
I' Python 3,6 (32-bit)
'ft Python 3.6 Manuals (32-bit)
,. Python 3.6 Modul~ Doa (32- Click here to open IDLE,
Python's own interactive
◄ Back
environme nt.
I - fJ I ' LJ.
Pyth on GUI Shell IDLE lets you save th e en tire session (commands followed by their results
. • - as it appears on screen) but that
is not the Python program /scn.pt cont · · only the instructions .
amin g
co•1iP UTE~ sc•ENCE \".i'iH P! T!--' C', - ,\
104
(iv) Click File ➔ Sa v e and then save the file with an e,tension .py. The Python program.-:; has
.py ex tension [Fig. 5.2(r)J. For instan ce, we g,n L~ th 0 name to our program as Hell o.py.
-----==------
- ~ •l)ntitw,d""
--------- ---- j -... s- ol..J
ill!] Edit ~ Run Opt,cru Wut~ Help C I... . .,
N- Wiruf1""' Ctrt•N 0
Ope, .•. Ctrt•O
Rl'Cent Fill!S
Olh
Opim Module._ A!t• M
Class Browser Alt• C •ec~Pltct1 tfttlrucl•
Path BrawsEr l S l',1hen '1 ,,'011 1,11
Figure 5.2 (c) Save file wit h .py extension with File ➔ Save command (Scri pt mode).
Now your program would be saved on the disk and the saved file will ha ve .py extension.
(ii) Click Run Run Module command [Fig. 5.3(a)] in the open program / script file's ,•,indc,,,-.
➔
I
program scnpl.
> > j
/ Type "copyright", "credits" or "licen se() " for more Information .
I>,:, I
Hello Word ! applied Run Module
command.
(You can see complete
1 From the Navigator window, click on Launch below jupyter notebook tile.
,,,
A~NaW19 1tor
• E.nvironmen~
0 0
Jupyterlab notebook
1'll Learn\rg
.n e .. t e nslt.l e e n, lronm ent for ln::eracti-- e Y.. eb•bu ed lnte ract;, e camputlno
not e b oo ► endro nm ent. Edit and r u n
and r e producibt e co mput.ing bu ed on t he
J•J O:te r No t.ebcoi •nd :.rchl te c ture hu m.ln·r u d, bl e do c;; ,, hlle de , cri oln g t he
d.sta 1n1l SI L Click here to launch
jupyter notebook.
0 0
qtcons.:,Le
• l< 5.:1 1t r,rlt1 • fll\ r t ~ n 0 • ■ I.JP n e l'lt
P,.Qt GU , Chtt Sl..t P~ft.1 11\hn « fii] 1Jf 1U
fn.1Aonm e nt Po., , , tut P rhoJn \U! ,,tt\
p,,-ei,,c,r multilll"I« ~ lt,tl g ,1,1 ltn i mu
ed , Uh.ld • d llin o , 1,,[ ■• ·t • tU tl/\ ,J
h ,g "UQhc,ng , gr1pr,ic,I ~ Utlpi ar,d l'ne te
d•lluQQl!'l'iJ • rd lnt1a ,pt .'.t11;in t u tu U
Click hare to launch
spyder.
Fee1etc
D
...
. . . . . . . .. . .. . . . . . .. . .....
lso be installed separately, without Anaconda also .
Please note that jupyter not ebook can a
COMP UTER SCIE N CE WITH PYTHON - XI
106
·
Since jupyter notebook 1s a w eb ba sed comp ul1·n g en v11· .o n m c nt , it w ill be laun ch ed in a
,,veb browser.
Your w eb browser wi ll n ow sh ow y o u notebook dashboard (see be low)
Ii Cl !!!I ~3:-ti
C CD loca 1-c,s:
Fies
Li:, -::·ac ~
P,'thon 3
J months ago
-ext f ,112
:, hours ago Fod er
6 months ago
Figure 5.5
4. On the notebook dashboa rd, click at dow n-arrow n ex t to New b u tton and select
Python 3 to create a n otebook for executing Python 3.x co d e. (see fi gu re above).
= ,nl ~
<(,
JUpyter ~
Name of new
notebook
Figure 5.6
[hopte r 5 : CO MPUTATIO NAL
THINKING AND
GETTING STA RTED WITH PYTH
ON 107
Inte ractive Mo de
U"titft d3
,
C <D loca lrost
Jupyt er Unt1tled3
, Ju py ter Un titled3 To run the code in
current code cell ,
click here
r •
Figure 5.7
• na,.,e
Specify name to
Enler 3 ne t, nol~bool
Q M R•Jn ■ C ►► cc"t your python script
()
••• ~- ,,r t1 r I
I··,
pri " : ("ne_l:: ,:or ld" )
Py•~cr· )
pri rt( I a, progra~~1-g ir
A python script
having multiple
python commands
Figu re 5.8
COMPUTER SCIENCE WITH PYTHON - XI
108
(c) Click on SJ VC icon first lo saw ii.
(d) Click Run to run your script.
Hc.1111 ,c u tr JI
l, l r r •t ,
l=.J
,>r t ( e Jo 1,orlcl'')
'( I m i.,1'cgrarr.Mi g in h the,
t,ello ,1orld
I am progr awmi ng i n Pyt hon
1'1 [ ; :
Figure 5.9
(e) You can check in the notebook dashboard, which is open in another tab ; it will
show you the name of your currently saved script.
c::, @I
C CD localhost
*
"It--<-;
Ju pyter _ogcut
. ;
••
,, ct
Python 3.6 .4 lt«•eccnd~, Ire -:e• •-••, , . ," --~-
18.2 1 : 59 ) [~SC v. 1908 32 Dlt 'lr•e • .
Type " copyri g,,t •, "c red1h" or 'L ·rs~ · • · , a,:,r•
info rca ti Of\ .
I n [ 2 ]: \ !Python Consok>
Figu re 5.11
Interactive Mode
To work in interactive mode in Spyder IDE, type your cornmand(s) in the !Python console
pane of spyder window. It will give you the output of the command there itself. ~ i:p.m·
above where we typed command :
pr int( "Hello")
in the IPython console pane and it gave us the result below it.
Script Mode
To work in script mode in Spyder IDE, type your script' s commands in the editor pane.
¢) To start a new script file, click File ➔ New File .. .
¢) To save current script, use command File ➔ Save or File ➔ SaveAs.
¢) Python scripts have File extension as .py.
COMPUTER SCIENCE WITI I PYTI ION XI
110 ~
• S1, e fol t
« CS P),thon d (20181 ► Chap Ol
(Fii;'l
Ctrl• N Create new script fil e N,: fc,l<J,r
IJ Nev. fife...
tfo,,nfoad1
., • I 11 JI ► t '
Ctrl -,. Q Recent Placts ,. HW
• Open...
1c,at<h .. 01~ • Shon,
Open last closed Ctrl .. Sh ift+ T
O~en recent L,bra nes
J .,
l
• Documents
Sa.c (trl•~ Music
-t • - · • Save commands Make sure to select
Save as type by
S.,ve as... Ctrl +Sh ift+ S 1 • •
clicking this arrow, as:
S.,v e copy as... .--- : ~ Horneg ro up
Python flies
Revert ,_--._ __,,... : "' Com puter
• ♦♦ ..., Local D,sk (( :) .,
To see •~ Fil e na me: HW.p>I
Figure 5.12
!.:&:lr•t:~~~ ~ ;:~•
::: ~ ., D Run you r script by • ' Q.
clicking here
]..•
frort c,f 1t, <:ither e,ri th<- Ed •c.r
or t.re Console.
9
•• ti)(
•• ne l lo
◄ ► hello.py •
j
(iv) Save the file w ith proper ex tension.
For this, use com mand File ➔ Save or
press Ctrl + S fro m the keyboa rd .
In the Save dialog that appear s, w rite
the name of the file and give an
extensi on .py. We h ave nam ed the file
as hello.p y.
(/.i} Gt1 the> foldL'r where \'~)U ~"' l' d tlw t1k . .
.
l ( th ' f,rompt J
n I pres" enter .
(iii) Type Lhl' fr,llowing l''omnu nu.i •
111 I rnn o l
I.
I • ' I'
(
.
1
J run our program hello.py :
That 1s Wl' should t\'J)l' h)lhnv m ~ comtr1iln c.1 1<l 1.:•omni
r •· •'"
eduplllar~FLASH: - /o.skto p
FiltEdit \'tew Scarl"h Terminal Help
:dupl lh r@FL ASH : ~S cd Desk~ ---
up\\\ar iFLAS H : -/ D~ s kto ~ python hello. Y ~
(ii: ') lt will compile and run your progra m . You ·11 . , . the ou tpu t of tht'. progra m in the
w 1 sec
termin al " -indow .
To create this,
2. Start new file (File ➔ New File) and type the follow ing text
in the ed itor ,\'indo,,· :
W"'ly F1rc;t Program
print ( "i,ello World ! ")
You can use the command ed. Alternatively, open files (press Windows key and
search for files .) Go to the correct folder.
Right click in the empty space and click "Open in Terminal".
9 There is no concept of extensions in Linux however, sublime text uses these
extensions to identify the fo rmat and highlights
the syntax accordi ngly. You can externally set the syntax format as well. But
we are not covering that.
te r 5 : COMPUTATIONAL THI NK ING
Ch aP AND GED ING
STARTED WITH PYTHON 113
3.6) _ _ _ __ _
_n __
~1J SP1-:__ (Pytho
[j NEWfile... Ct rl +N
i!j X
o pen... Ctrl +O
~
Open last closed Ctrl• Shift-,. T
Open recent ► )
t < I
Ctrl+S
... S3 e
(trl • Alt•S
S3 e ?II
I , Here ,oo can get
6 P• int ( 1
Ctr1 +Shift+ S ) '1elt> of any ob}ed
:.., Save as... - - - - r,,,,._,,,, . ._
Save copy as ... 8 '--" nrcibe- ""'u;l b~ ,,elp
-:..,
Revert Type code fo r ~cr =o
~ you r progra m ~ UllWl!!! l ~
In [ 1):
~ ra, =- ~ x
&.l'Or -E:~V •ont' tf\'l.p y
C: 'f'-N.py - 0.
l
.\
..••••
Here you can get
I • • "
]
• l
.
But Py th on gav e you JU 1' 1c's out pu l as :
SI one 11 •
He llo wo rld I
. b is a com m en t in Py tho
1 n . Th at is, it is
Th e rea son bei ng tha t any h.nl'"' Jy1 l be ins w ith a # s~m o
t.~ g . Py thon will comp lete ly ign o re all the lines starnn
for the p rog ram me r ,s 111
. f
·orm al!on onl y , g
wit h a 4.
Unders1onding print( )
. . t() fun ction 1°. Yo u can use
To print or display out pu t, Py th 3 pri nt( ) as
on .x Prov1des pnn
pn ntt <.ObJects to be pri nte
d> · · ·)
e.g. , wh en you wr ote
------ . "ff ,,[/o H'orld !'' i., the
Str111g
~ ~
prin t( ) object tu be printed
stat em ent 1
pri nt ( "H ell o Wo rld !")
it printed :
Hel lo World!
it will print
t~y name is Misha
...---
pri nt ( "H ell o World ! " )
' Hey th ere " ..-- - Lrwr! O{'(' /Wlg and clo ,iu~ Ouutclliu
mart, do 1101 11wrth 11
, /P- - - - - - - - - - - - - - - - -
WO RKI N G IN SCR IPT MO DE
Progress In Python :
~ •e
pon ent- boo k - Pro gress in ( 0 ,,-- 0
Pleas e che ck the pra ctic al com
( Scie nc e wi t h Pyth o n and fill it ther
e in PriP 5 .2 und er C ha p•er 5 a
pra ctic ally doin g it on the com p
ute r.
fter
LET US REVI SE
solurions
l Thin king refers w the collective thou ght processes invo lved in formulating problrms and
Computationa
be effectively carr ied out by a com purer.
so that they are represented in a form that can order co understand
process of brea king dow n a big or com plex prob lem into a srt of sma ller sub-processe s in
The
mpo sition.
a problem or situation better, is known as deco and within sma ll,
lool<ing for simi larities or paccems among
Pattern recognition refers to observing or iently.
help solve more complex prob lems more effic
decomposed problems; the identifi ed patterns lem and suppressing
ssing on in forma tion relevam to a comexU prob
Abstraction or Data abstract ion refers to focu
other details. such that
n refers to iden tifyin g com mon or shar ed characteristics between rwo domains or problems
Generalisatio
or applied to the othe r.
models or solutions of one could be adap ted ucing O desired
is a sequ ence of step s that solves a prob lem by working on some input data and prod
An algorithm algorithm .
n involves both creation and execution of an
outcome (effective solution). Algorithm desig
coMPUT ER SCIENCE WITH PYTHr
..J ► •
11 6 a~ 1991.
m 1 rbn
1 ' y •
\Ii RO\SIJ11f fr
•• P>thon "•as drvrloprd ,.,,, .dc;uuln ,..~n :, ,ros~•platform :> ee and open ~urcr:
• Pylhon offer~ follov.'mq a van1og< :> <omJtlt'l <'
:1 easy ro u~e ::, e\r~r{'.l,sl\ff' :., Nor strong on Type-b1ndin!J
• J V iJ v,•rl I!>•
•: Pvlhon oli.o has thr..t'' 1,m11011om, 11h1 :'111~ th,111 c ' a • if) Script mode.
, I • .;> f 1-S'>t'I ' r,,o(/f' (
:, Not the fo'>tr!-I an~utl~~ . (iJ /ltf" rncI IYt' ' \ c,o ndw,c hed berween com
In Pvrhon, onr cw1 wm /. ,n rwo dlfI• ,, nt wnyi. . I ,,rnr]rtlfll cmd rtlv, , oufpur , ma'1f1;
❖ · j ,n fmlll I> {1
,. .h .. m0dr do(•, ,1t1t ~ \'<' ' ·1111111uirn ~
-: lntt.: ram d fJeCcompiece ourpur
Jntrrnccit , mode ,~ !-UttiJMr fm 1r,1111q c(,cIr uri th<' proqram!I lat1 r an
,,(}gram\ and tfwn r
< St npt mvJr ,s US l ful for m-atmg I
• r vrhon rs on intc'rprrrrd lariguagr SI II
. 15
l5o called Python ,e .
P;thon 's ,ntcructive incerprf'tcr a
SoluboP . (c)
l~- Python is a Free and Open Source language. What do you understand by this feature ?
Solution. It means - to download Python, one needs not pay anything, because it is Free. An d i~s
source-code is also available, which can be modified/improved etc., because it is open-source.
13. What is the difference between interactive mode and script mode in Python ?
Solution. In interactive mode, instructions are given in front of Python prompt (e.g., >» or In[ 1:
prompts) in Python Shell. Python carries out the given instruction and shows the result there itself.
In script mode, Python instructions are stored in a file generally with .py extension and are executed
together in one go as a unit. The saved instructions are known as Python script or Python prt1~...-,am.
14. What will be the output of following code :
#This is a sample program
#to output simple statements
#p rint ("Such as")
print ( "Take every chance.")
print(" Drop every fear.")
Pick the correct output from thefollowing choices and give reason. T/Jis is a sample prosr,1111 Ii> 1utp11t si111plc
1
statements
(a) such as (b) such as (r) suc/J as