This program demonstrates the use of the Decimal class from the decimal module in Python. The Decimal class provides support for decimal floating point arithmetic, which is useful for precise mathematical calculations involving decimal numbers.
In this program, a decimal number res is created using the Decimal() constructor, which takes a string or a number as an argument. The sqrt() and exp() methods of the Decimal class are then used to calculate the square root and exponential of the number res, respectively.
The sqrt() method returns the square root of the Decimal object, and the exp() method returns the exponential of the Decimal object. These methods are useful when we need to perform mathematical operations with high precision, as they can handle decimal numbers with arbitrary precision.
The print() function is used to print the results of the calculations to the console. The output shows the original decimal number res and the corresponding square root and exponential values. Overall, this program demonstrates the use of the Decimal class and its methods to perform precise mathematical calculations involving decimal numbers.
from decimal import * res = Decimal("64.0") print("Square root of ",res, " is :", res.sqrt()) print("Eresponential of ",res, " is :", res.exp()
Square root of 64.0 is : 8.0 Eresponential of 64.0 is : 6235149080811616882909238709
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions