Saturday, 19 March 2016

How to use numbers in Python ?



EXAMPLE PROGRAM
# Numbers
n1 = 1
n2 = 2.5
print(type(n1))
print(type(n2))
print(n1)
print(n1 + n2)


Output
<class 'int'>
<class 'float'>
1
3.5




RUNNING SOME EXAMPLES ON PYTHON SHELL
>>> a=3    # Name Created
>>> b=4
>>> a+1, a-1   # (3+1), (3-1)
(4,2)

>>> b*3, b/2
(12,2)
>>> 1 / 2.0
0.5
>>> 1/2
0
>>> 1 % 2
1

No comments:

Post a Comment

Note: only a member of this blog may post a comment.