In this tutorial we explain Python Tutorial – Mathematical Functions. In the above tutorial we shared video tutorial. Python includes the following functions that perform mathematical calculations.

Number abs() Method

The abs() method returns the absolute value og x i.e., the positive distance between x and zero.

Syntax:

abs(x)

x – This is a numeric expression

Number ceil() Method

The ceil() method returns the ceiling value of x i.e., the smallest integer not less than x.

Syntax:

import math

math.ceil(x)

x – This is a numeric expression

Number floor() Method

The floor() method returns the floor of x i.e., the largest integer not greater than x.

Syntax:

import math

math.floor(x)

Number exp() Method

The exp() method returns exponential of x: e pow(x)

Syntax:

import math

math.exp(x)

Number max() Method

The max() method returns the largest of its arguments. i.e., the value closest to positive

infinity.

Syntax:

max(x,y,z….)

Number min() Method

Returns the smallest of its arguments ie, the value closest to negative infinity.

Syntax:

min(x,y,z,…….)

Number pow() Method

Returns the value of x pow y

Syntax:

import math

math.pow(x,y)

Number round() Method

random() is a built-in function in Python.

It returns x rounded to n digits from decimal point.

Syntax:

round(x,[,n])

Number sqrt() Method

The sqrt method return the square root of x for x>0.

Syntax:

import math

math.sqrt(x)

Let us see a simple program in Python using mathematical functions

Save it in desktop and run the code.

Random Number Functions

Random numbers are used for games, simulations testing and privacy applications.

Python includes the following functions that are commonly used.

Number choice() Method

Returns a random item from a list, tuple or string.

Number randrange() Method

Returns a randomly selected element from range(start,stop, step)

Number random() Method

Returns a random floating point number in the range[0.0,1.0]

Number seed() Mehod

initializes the basic random number generator.

Number shuffle() Method

Randomizes the items of a list in place.

Number uniform Method

Returns a random float r, such that x is less than or eqaul to r and r is less than y.

Let us see a program in Python using random() functions.

save it in desktop and run the code.

Trignometric Functions

Python includes the following functions

acos(), asin(), atan(), atan2(), cos(), hypot(), sin(), tan(), sin(), degrees() and radians().

Let us see a program in Python using Trignometric functions.

Save it in desktop and run the code.

This is about Number functions in Python.

**Download:**

## Leave a reply