Sunday 19 March 2017

Python programming part-2 Simple Operations

Simple Operations : Part-1


Python has the capability of carrying  out calculations . Enter a calculation directly into Python console , and it will output the answer .

>>> 2+2
4
>>> 5+4-3
6

Question:
How dose this code output ?
>>> 1+2+3

________________________________________________

Simple Operations : Part-2

Python also carries out multiplication and division , using an asterisk to indicate multiplication and a forward slash to indicate division.

Use parentheses to determine which operations and performed first.

>>> 2 * (3+4)
14
>>> 10 / 2
5.0

Question :
Which option is output by this code ?
>>>(4 + 8) / 2

________________________________________________

Simple Operations : Part-3

The minus sign indicates a negative number . Operations are performed on negative numbers , just as they are on positive ones .

>>> -7
-7
>>> (-7 + 2) * (-4)
20

Question :
Fill in the blank to make this code correct .
>>> (___5 - 1) * 3
-18

__________________________________________________

Simple Operations : Part-4

Dividing by zero in Python produces an error , as no answer can be calculated .

>>> 11 / 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero

__________________________________________________
                                                                                                   


EmoticonEmoticon