Course Content

  • Math Module

Course Content

Python Math Module

Hello guys. Welcome to LearnVern. In the last topic we saw a random module.

Today’s topic is the Math Module.

What is a Math Module?

Math module is used to do a mathematical task in Python.

Python gives this facility in the Math module.

If you want to find any factorial, round off, square root...you can do all of it through the Math Module.

These are some of the operations of the Math module.

Such as Factorial, if you want to find out Factorial, you can use this function available in the Math module.

Second is the Ceil (pronounced as in Ceiling) function which rounds up the value.

Next is Floor. Floor will round down the value. Means it will take the nearest lower version.

And Ceil will take the nearest upper version.

Same is the square root. You must already be knowing square roots as we all have surely studied the same in our childhood.

Python has a sqrt function which will take the square root of the value.

Let us see how we can use this Math module practically.

First of all, you’ll have to import the math module and then only further use the math operations.

Let’s begin the practical part.

I’ll open Jupyter.

Before using any operations, you have to import the math module.

I’ll show you both the ways to import a math module.

You can directly write Import & then Math. Or the other way is…

Like we saw in Random. From math import and then the name of the function you want to use.

You can import math modules in these 2 ways, okay?

Let’s work with math operations.

First is Factorial number.

I’ll write down Factorial here.

Now how will we use it?

First of all, I’ll import the Math module.

Now we can use any math operations.

Suppose I print math here . (dot) tab.

If you want any suggestions such as factorial functions etc, there is an option in Jupyter, called Math . (dot) tab & you will get all the functions in it.

I want to use factorial right now so we got it here.

Now we have to pass the parameter.

You will pass that particular number whose factorial you want to find out.

Suppose I want to find out 9. It found the factorial out.

We will find out a couple of more number’s factorial in the same way.

I’ll write here 6.

It found out the factorial of 6.

Let’s find out the factorial of 12 as well.

As you can see, it found 12’s factorial as well.

So this is how the factorial method works in the Math module.

Now we will use the next method which is Ceil.

I’ll write Ceil here.

First of all, I’ll import my math module.

Now we will print. Remember in Ceil, the nearest upper version of the value will be found.

Math . (dot) Ceil function in which I’ll take 1.4.

It will round up all the float values.

It brought the nearest to 2.

This Ceil brought the nearest value of 1.4 to 2 but this one is upper.

We will print Math . (dot) ceil 5.3. And it brought 6.

Let’s check more such values.

Let’s go for the negative value this time. -5.3. Then it brought -5.

This is how it will bring the nearest values to the upper round up.

Let’s work with the Floor method now.

We will import math first.

I’ll print Math . floor. Suppose I write 0.6, it will bring 0.

It will bring the nearest down value.

Ceil will bring the upper value & float will bring the down value.

Clear?

I’ll copy paste it.

I’ll change the value to 1.4.

Run & it will show 1. Previously it brought 2 and in Floor, it brought 1.

Ceil upgrades & Floor downgrades.

So this is how my floor function works in the math module.

Next function is the square root function.

Import math module.

Print math . (dot) S. Will bring square root function.

Suppose I take a square root of 10. Here it is.

Let’s check other values as well.

Suppose I took 100, it gave me a square root of 10.0.

Square root function helps in finding the square root of any value.

So this is how you can use the functions of the math module.
What did we learn today?

We learned how to import math module, we checked the factorial function, we saw how to use the Ceil function as well as the Floor function.

We also worked with the square root function.

Our next topic will be File Handling..

Thank you guys.

FAQs

The Python math module provides functions that are useful in number theory as well as in representation theory, a related field. These functions allow you to calculate a range of important values, including the following: The factorials of a number. The greatest common divisor of two numbers.

The features of this module are that it is easy to work with due to its large amount of different mathematical operations that can be done and it has a lot of built-in constants which can be helpful in many situations.

The Python Math module is an important library for performing mathematical operations in Python. It provides the tools to compute mathematical expressions, calculate numeric values, and it has methods for trigonometric and logarithmic calculations.

The math module contains functions for calculating various trigonometric ratios for a given angle. The functions (sin, cos, tan, etc.) need the angle in radians as an argument. We, on the other hand, are used to express the angle in degrees.

The Python math module provides functions that are useful in number theory as well as in representation theory, a related field. These functions allow you to calculate a range of important values, including the following: The factorials of a number. The greatest common divisor of two numbers.

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
Apple App Store
598K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
15K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere