Working With Python Math Module
hive-163521·@leoumesh·
0.000 HBDWorking With Python Math Module
<div class="text-justify">  <center>[Image Source](https://levelup.gitconnected.com/learn-the-python-math-module-9c2c516ea37c)</center> Python has one of important module which is math module that contains set of functions, classes and variables that you can use to do various basic to high level operations. In this post we will see examples working with such module. First we need to import module in our program where we gonna write code so that we can have access to functionalities inside the module. The syntax is pretty simple i.e. `import math`. Now lets see a simple program that prints the value of π (pi). We can do by writing: `print(math.pi)`. If you run the code, you will get the following output:  Similarly to find the square root of the number, you can use `sqrt()` function as below:  In the same way there is another function `isqrt()` that returns the square root value of an integer but in rounded form to the nearest small integer.  In order to find the one number to the power of another you can use `pow()` function that takes two argument. In the following picture you can see 12 to the power of 2 being printed.  We have heard of ceiling in mathematics that returns a number that is just greater than or equal to the given number. In python, we can use `ceil()` function to find the ceiling of a number. A simple program would be `print(math.ceil(477.318))` that would show us the following output:  Another function would be `factorial()` that you can use to find the factorial of any number like below:  Also you can use `comb()` function for combination that allows you to show how many ways a particular number can be selected from a set of numbers.  In the same way, in order to find the HCF or GCD you can use `gcd()` function. `print(math.gcd(24, 40))` will print the greatest common divisor which is 8 as below:  In the next post, we will see about more mathematical functions that can be used to perform certain basic operations that we had learned throughout our whole life in python. </div>
👍 leoumesh, ewkaw, sharpshot, helcim, thepeakstudio, kph, logic, steemcleaners, hivewatchers, eturnerx-honey, msp-makeaminnow, we-are-palcoin, yintercept, eturnerx, yuki-nee, riovanes, irivers, yggdrasil.laguna, stemgeeks, stemcuration, abh12345.stem, brofund-stem, adamada.stem, solominer.stem, slider2990, cd-stem, stuntman.mike, dorkpower, stemline, star.stem, babytarazkp, saboin.stem, sillybilly, notak, he-index, blainjones, elianaicgomes, cbridges573, smartvote, krishu.stem, pfwaus, limka, harpreetjanda, enforcer48, scholaris.stem, stem.alfa, holovision.stem, spaminator, rupinder, gurseerat, drifter1,