image
image
image

Mathematics in Python

image

To carry out mathematical functions, Python offers modules like random and math.

Start IDLE.

Navigate to the File menu and click New Window.

Type the following:

import math

print(math.pi)   #output:3.14159....

print(math.cos(math.pi)) #the output will be -1.0

print(math.exp(10))  #the output will be 22026.4....

print(math.log10(100)) #the output will be 2

print(math.factorial(5)) #the output will be 120

Exercise

Write a python program that uses math functions from the math module to perform the following:

a. Square of 34

b. Log1010000

c. Cos 45 x sin 90

d. Exponent of 20