Intro To CS Lec04
Intro To CS Lec04
Expressions
<class 'bool'>
True
False
Boolean Algebra
Boolean Expressions
False
True
Operator Precedence
a and b or c
(a and b) or c
not
a and (b or c)
Functions
Function
perform a computation
Abstraction
Function types
abs(-2) 2
max(7,8,12) 12
“Calling” functions
Argument
>>> type(32)
Arguments
An argument is a value we pass into the function as
its input when we call the function
We use arguments so we can direct the function to do
different kinds of work when we call it at different
times
We put the arguments in parenthesis after the name
of the function
Modules
Import
>>> math.sqrt(20)
Math module
>>> math.exp(math.log(10))
>>> math.cos(60)
Definitions and Uses
statements
Say hello twice
def hello_twice():
print(‘hello’)
print(‘hello’)
>>> hello_twice()
def print_chorus():
print(“Girls hit your hallelujah …Woo!.”)
print(“Girls hit your hallelujah …Woo!.”)
print(“Cause uptown funk gon’ give it to you”)
def square(num):
print(num*num)
>>> square()
>>> square(3)