# Math Functions

Chapter 9- Python, Beginner Level (My Study Notes)

Last Update: 2018-12-12

**Description**

The math function is under math module. Thus, you need to import math module before you com use it.

**Content**

TABLE OF CONTENTS

Chapter 1

Start Learning Python, Download Python, Adjust Font Size

Where is the starting point of learning a new programming language as I know nothing about programming? Of course, downloading the Python at python.org

Chapter 2

Reserved Words in Python

I am glad to explain Python reserved words here, some of them are difficult to understand without practising. If you feel bored, you can feel free to skip this study note and go to next directly. As my own experience, an effective way to learn programming is do-it-yourself. Thus, you should practise the reserved words while reading.

Chapter 3

Python Calculations

Basic calculation operands in Python: Subtraction, Multiplication, Divison(float), Divison(floor), return the remainder

Chapter 4

Variables in Python

- Create and use variables

- Construct a program in a text editor, save and retrieve the file.

Chapter 5

Input Function

It is used to ask a user to input a value.

Chapter 6

Conditional Execution

Conditional execution is mentioned in this study-note. This study-note includes Boolean expressions, comparison operators, three logical operators, Pass statement, Nested Conditionals and try and except

Chapter 7

Built-in Functions

This study note is talking about the high usage built-in functions: max(), min(), len(), int(), float() and str() built-in functions.

Chapter 8

Random Numbers

How to use the Random module to generate a random number or a set of random numbers are introduced.

Chapter 9

Math Functions

The math function is under math module. Thus, you need to import math module before you com use it.

Last Update: 2018-12-12

What programming language should you learn? My answer is Python. Would you like to learn Machine Learning/ Statistics/ Data Analysis or...in the near future? It doesn't matter what's your purpose, if you need to work with figures and data, you can get benefit from this easy-to-learn and easy-to-use programming language.

Chapter 9- Python, Beginner Level (My Study Notes)

Last Update: 2018-12-12

The math function is under math module. Thus, you need to import math module before you com use it.

**Content**

The math function is under math module. Thus, you need to import math module before you com use it.

>>>import math

Now, you can use the functions provided by math module.

math functions are called in following way:

math.function_name()

Specify the module name + '.' + function name

This is called dot notation.

For instance, we need to use the log function, so:

math.log()

>>> x=math.log(5)

>>> print(x)

1.6094379124341003

After you typed

math.

a select box appears, you can see all math module functions. The select box sometimes appears late.

Create a function

Create a function is handy, you just need to use the following format:

def function_name:

def = define a function

Then, give it a space before the function name.

Finally end it with colon(:)

For instance, I would like to create a function for doing a multiplication, I give the function name calculateIt. The function needs to have 2 arguments, a and b, then, the function return c. The c is the product of a and b.

* = multiplication sign

>>> def calculateIt(a,b):

c=a*b

return c

>>> print(calculateIt(3,5))

15

The first line of the function is called the header:

def calculateIt(a,b):

and the rest of the function is called the body:

c=a*b

return c

After you typed

math.

a select box appears, you can see all math module functions. The select box sometimes appears late.

Create a function

Create a function is handy, you just need to use the following format:

def function_name:

def = define a function

Then, give it a space before the function name.

Finally end it with colon(:)

For instance, I would like to create a function for doing a multiplication, I give the function name calculateIt. The function needs to have 2 arguments, a and b, then, the function return c. The c is the product of a and b.

* = multiplication sign

>>> def calculateIt(a,b):

c=a*b

return c

>>> print(calculateIt(3,5))

15

The first line of the function is called the header:

def calculateIt(a,b):

and the rest of the function is called the body:

c=a*b

return c

Both terms sometimes are confusing.

Using the above example:

def calculateIt(a,b):

a and b are argument which the function calculateIt takes them. Inside the function a and b are parameters for doing a multiplication. The product c is a parameter as well.

The print() which allows to print something more than one:

>>> print('echo '*5)

echo echo echo echo echo

It printed echo 5 times.