29 Apr '17

Shiva Prasad

A collection of source codes that I wrote in VB 6.0, ASP.NET, PHP, C#.NET, VB.NET and JAVA in a course of my career as web developer and software engineer that I would like to share to my fellow programmers. Some of the codes here is not my original work that I found over the Internet and Books while I’m learning how to program. I hope you find my work useful in your learning in programming. Please share my work to other people also who interested to learn the basics of web development and programming. Thank you very much and Happy Productive Programming Everyone.

Python Tutorial – Mathematical Functions

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:

Python Tutorial – Mathematical Functions

download project report

Related Posts