Computer Science

Import the above module basic.py and write statements for the following :

(a) Compute square of 19.23.

(b) Compute floor division of 1000.01 with 100.23.

(c) Compute product of 3, 4 and 5. (Hint. use a function multiple times).

(d) What is the difference between basic.div(100, 0) and basic.div(0, 100)?

Python Libraries

2 Likes

Answer

The statements are given in the program below:

import basic

# (a) Compute square of 19.23
square_result = basic.square(19.23)
print("Square of 19.23:", square_result)

# (b) Compute floor division of 1000.01 with 100.23
floor_div_result = basic.floordiv(1000.01, 100.23)
print("Floor division of 1000.01 by 100.23:", floor_div_result)

# (c) Compute product of 3, 4 and 5
product_result = basic.mul(basics.mul(3, 4), 5)
print("Product of 3, 4, and 5:", product_result)

# (d) 
result2 = basic.div(0, 100)
result1 = basic.div(100, 0)
print("Result of basic.div(100, 0):", result1)
print("Result of basic.div(0, 100):", result2)

Output
Square of 19.23: 369.79290000000003
Floor division of 1000.01 by 100.23: 9.0
Product of 3, 4, and 5: 60
Result of basic.div(0, 100): 0.0
ZeroDivisionError
Explanation

(d) basic.div(100, 0) results in a ZeroDivisionError because division by zero is not defined whereas basic.div(0, 100) results in 0.0 as the quotient of '0 / 100'.

Answered By

2 Likes


Related Questions