



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These lecture notes cover the use of the math module in python, focusing on various mathematical functions and constants. Additionally, the concept of 'fruitful' versus 'void' functions is explained, with examples and exercises provided for better understanding.
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Today’s Topics ...
Homework
The math module contains many often used mathematical functions
import math help(math) # to browse functions available math.ceil(3.9999) # round up to next highest int 4 math.floor(3.9999) # round down to next lowest int 3 math.hypot(3, 4) # square root of a2 + b
math.log10(100) # the log base 10
math.log(16, 2) # the log base 2
math.sqrt(25) # the square root
To round a float, use the built-in round function
round(3.2) 3 round(3.6) 4
When importing modules ...
Void functions actually return the special None value
result = print("Hi") Hi print(result) None type(result) <type ’NoneType’>
Return values using the return keyword
def succ(x): x = x + 1 return x
succ(1) 2 y = succ(2) print(y) 3
... but no statements after it is called will be executed
Q: What is returned?
z = 1 def f(x, y, z): result = x + y return result new_result = result + z return new_result