Q. (a) In Python shell, type the following:


import math


Now type the following statements one by one and look what happens:


(i) math.sqrt(49)
(ii) sqrt(49)
(iii) math.fabs(-3)
(iv) fabs (-3)


Answer :-


(i) 

>>> import math
>>> math.sqrt(49)
7.0


(ii) 

>>> sqrt(49)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    sqrt(49)
NameError: name 'sqrt' is not defined


(iii)

>>> math.fabs(-3)

3.0


(iv) 

>>> fabs(-3)
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    fabs(-3)
NameError: name 'fabs' is not defined



(b) Now quit the Python shell. Again, restart Python IDLE shell and type
from math import *
Type the same set of statements given in part (a) i.e., (i) to (iv). Log what happens


Answer :-


>>> from math import *


(i)

>>> math.sqrt(49)
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    math.sqrt(49)
NameError: name 'math' is not defined


(ii)

>>> sqrt(49)

7.0


(iii)

>>> math.fabs(-3)
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    math.fabs(-3)
NameError: name 'math' is not defined


(iii)

>>> fabs (-3)

3.0

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post