



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
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