KnowledgeBoat Logo

Computer Science

After importing the above module, some of its functions are executed as per following statements. Find errors, if any:

(a) square(print 3)

(b) basic.div()

(c) basic.floordiv(7.0, 7)

(d) div(100, 0)

(e) basic.mul(3, 5)

(f) print(basic.square(3.5))

(g) z = basic.div(13, 3)

Python Libraries

1 Like

Answer

(a) square(print 3) — print function should not be there as parameter in the function call. So the correct function call statement is square(3). Also, to call square function without prefixing the module name, it must be imported as from basic import square.

(b) basic.div() — The div() function requires two arguments but none are provided. So the correct statement is basic.div(x, y).

(c) basic.floordiv(7.0, 7) — There is no error.

(d) div(100, 0) — This will result in a runtime error of ZeroDivisionError as we are trying to divide a number by zero. The second argument of the function call should be any number other than 0. For example, div(100, 2). Also, to call div function without prefixing the module name, it must be imported as from basic import div.

(e) basic.mul(3, 5) — There is no error.

(f) print(basic.square(3.5)) — There is no error.

(g) z = basic.div(13, 3) — There is no error.

Answered By

2 Likes


Related Questions