17 September 2020

Functions and Math

Math Review: What is a Function?

function has three anatomical parts
    A set D of allowable inputs, called the domain
    A set R of allowable outputs, called the codomain.
    A rule f associating each element of the domain
    with some element in the codomain.  

functions are consistent: the same input yields teh same
output every time.

len is a mathematical function

domain: sequences.
codomain:  integer

Mrs wormwood says f(x) = 2*x + 5

domain = codomain = real numbers.

f(x) = 1/x  domain: all numbers except 0.




Many Python Functions aren't Math Functions

Mathematical functions must be consistent.
Mathematical functions have no side-effect.


The Three Traits of Functions.

What is a "pure" function? This is a matheamtical function.

Boss Statements: Conditional Logic

Truthy and Falsy (go to :30 to skip the ad) An object is truthy, if, when cast to a boolean, it returns True. An object is falsy, if, when cast to a boolean, it returns False. Let us do a quick review of the situaion so we know what to expect.

Numbers



Strings



Lists and Tuples



We will use the term predicate for an expression or function that returns a truthy value.

We will learn about three new boss statements. Here they are.

Getting information into a Program Today, let us discuss the function input and sys.argv.