You are on page 1of 5

PROGRESS IN COMPUTER SCIENCE WITH PYTHON _ XI

Progress
in Python Interactive Mode
Python

Start Python Anaconda Navigator and then Spyder IDE. Or you may also use any other IDE of
your choice.
On the IPython console perform this session

Python prompt as calculator


1. In front of Python prompt, i.e., In[ ] prompt, type following expressions one by one, by
pressing return key after every expression, e.g., -
In [l ] : 6 * 3
In [ ] : stands for input command
It will show output lines starting with Out[ ] :, e.g. : and Out [ ) : stands for output ;
0ut [2] : 18 here Python shows the output.


- ~-- 1:b• ~ ~I!,•~ )I ~ le~ t+ :Ii X ..,..,,......-~-
, > e- L_~ +_-:_~ ... +
"-'·,c-'.".....,,,,"""".,.,.,,.,,...._..,.___""
1

o -...,-a
- - ~ : • 1, •

1 • '"' - codi ng ; ~•t f - 8 - ~-


2 •••

.......
3 fl-uthor- : S u ai t •


6
7

In [1) , 6 • 3
0ut[1) , 18

It is not necessary to work in the j In [2) ,


mentioned 1IDE only ; if you have
any ,other development environ-
ment :loaded, you can work in that
also. Python 3.6 will work in the Ii
same way in all lDEs.

Don' t worry if all the results are not clear to you right % gives remainder,
now. Just note down any questions arising. All these e.g. , 7"2 w ill give 1
doubts will be solved slowly when you learn the •• means raised to power
e.g., 23 is 2 • • 3
Python data handling concepts.
I= means Not equal t o
3
Chapter 6 : GETTING STARTED WITH PYTHON

[Carefully notice, when you assign an expression to a name e.g., P = 2 + 3 in front of


prompt In[ ] :, does Python display anything ? When does Python display and
when not?]

Result (what Result (what


Expression Expression Python returns)
Python returns) ·

1. 6 * 3 iS 15. a= 8 % 3 No eotpul
2. 3 ** 3 Jt 16. a
2
3 6+2*4 l'-1 17. 3**2**0 No Oufpuf
4. (6 + 2) * 4 3.2 1
18. (3 ,.,. 2) ,.,. 0
i

. 5. 5- 3- 3 "- i 19. a+5 -+


6. k = 5 - (3 - 3) No,,OlJpu} 20. 3.0 ,. 0.5 (5

7. 9.0 ** 0.5
,.
so 21. 9.0 % 3 00

8. (S + 3.1) *S L( ;) . 5 22. - 9.0 % 4


30

9. S = 5.0 -(3 - 3.0) N{) {)u/pul 23. 6.2 % 4 :;

10. s 5-0 24. 2 <S TJ-W e

11. X = 12.0/4 No ou+puf 25. 3 < 5 and S < 3 Falb e ·


' '

12. 26. 4 < 3 or 6 > 7


X
3 .Q fake

13. 7 - -7 - - 7 27. 3 <= 3 TM e


J1
14. 8/6 ,.3333 . . .. 28. 4 ! = 5 lm.Je

. l
_J -
PROGRESS IN COMPUTER SCIENCE WITH PYTHON _ XI

Displaying vs . Printing

Please note that writing an expression or variable name in front of the Python prompt
( In [ ]: ) displays its value e.g.,
when you assign a value or expression using = , Python
In [ ] : S = 23 ~ - - - - - - - simply does the assignment but does not show anything.

In [ ] : S result of S di&playn
23 : . - - - -
In[ ] : S + 3
. . , _ - - - - result of expression S + 3 di&playn
26

Printing is done with print ( ) function call command e.g.,


In[]: print (S + 3)
26 - - - - - - - result of S + 3 printed.

You can display values only in interactive mode ; to display anything through script
mode, you need to use print( ) command.
(Next PriP session 6.2 will make you practice print commands in script mode).

2. Display and print the given values :


(1) 33 + 23
(i1) S == 24 + 9 (first assign 24 + 9 to S and then print (display S))
(iii) a == 3, b == 17, c == b - 10 (first assign these values to a, b and c in three separate
statements and then print/display them.)
(1)

lri CJ : 3 3 + J 3
OuH J : 56

(ii)

ln [ J : 5 = .2 ~t9
p>Dn+ (s)
33
Chop_ter 6 : GETII NG STARTED WITH PYTHON

(m)

\n ( J : a ., 3
In( J : ~"' I i
In ( ) ·. c = Lr - I 0
Ifl ( J : f ,.tin+ Co , lr , c)
3 If 1.

,,.

I ', l
6 PROGRESS IN COMPUTER SCIENCE WITH PYTHON _ Xi

. Progress
in
· Python
Working in Script Mode

Start Python Anaconda Navigator and then Spyder 1l"/f)E. Or,you i,na~ qlso u~ any other IDE of
your choice.

Open new File window


Click File New File in Spyder IDE.

1. Type following code (as it is) in the new window opened by IDLE
print (" Hello Nathan", "Hello Lalit ")
greetl = " Hello Nathan "
greet2 =" Hello Lalit "
namel = " Nathan "
name2 =" Lalit"
print (greetl, greet2)
print ("Hello", namel, ",", name2)
namel = " Purvi "
name2 = " Hunar "
print ("Helld', namel, ",", name2)
Save program file
Save the file by pressing Ctrl+S or File Save command
Run program
Click Run Run Module command or press FS.

Notice the output and compare it with code.

Hdlo No+ho.ll Hv.Jo La.}jt


H<l.1 0 t-JothOJ) tl<l.lo L~+
HelJ 0 NaH-1 a11 , LcM
HeJJo PU}( vi , HUI\o>t

You need not worry if certain things are not clear to you right now. Just watch out for
now ; everthing will become clear to you soon ©

You might also like