Lecture Jan 7, 2020
● Syllabus, PCRS, and general introductions
Lecture 02
● Terminology
○ 1+2
■ Operators = +
■ Operands = 1, 2
○ -3
■ Operator = -
■ Operand = 3
● Order of arithmetic precedence
○ ()
○ **
○ - (negative sign)
○ *, /, //, %
○ -, +
● Python documentation
○ Ex. round(number, ndigits=None)
■ Round = function
■ Number = first argument
■ Ndigits = second argument
■ = None
● If the second argument is provided, round will use the provided argument.
Otherwise, round will use the value None for the second argument
● Ex. round(42.54335, 2) = 42.54
● Ex. round(42.54335) = 43
● Ex. round(1234.5678, -2) = 1200.0
PCRS Jan 15, 2020
● Argument = values given
○ Ex. data = 3
data2 = 7.5
result = min(data, data2)
● Parameters = values not given
○ Ex. def f(data):
return data * 0.5
Lecture 03 Tues Jan 14, 2020
● Terminology
○ x=1
■ x has gets 1
■ x refers to the value of 1
■ x has a memory address of id1
■ memory address id1 is stored in variable
● Naming variables
○ Starts with a letter or underscore only
○ Contains only letters, digits, or underscores
○ Case sensitive
PCRS Weds Jan 15, 2020
● Function design recipe
○ Examples
○ Header
, ○ Description
○ Body
○ Test
Lecture 04 Thurs Jan 16, 2020
● Midterm expected for first week of february
● Worksheet “Function Design Recipe”
○ Strings always have quotes
○ print(‘yes \n no’)
yes
no
○ print(‘yes \’ no’)
■ yes ‘ no
○ repeat_word(‘smiles’, 0)
■ ‘’
Lecture 05 Tues Jan 21, 2020
● Python considers strings as values too, when it comes to strings
○ Dictionary order
■ ‘abs’ < ‘bsd’
True
■ ‘bs’ <= ‘asd’
False (python evaluates one character at a time, b with a, then s with s)
■ ‘B’ <= ‘a’
True (all lowercase letters come before all uppercase letters)
■ ‘’ < ‘b’
True (empty strings come before all lowercase and all uppercases)
● Priority
○ Arithmetic functions and amounts (greater, less than, etc.) are evaluated left to right
■ Ex. 1 + 1 == 2
True (better to write as (1 + 1) == 2)
● Boolean Operators
○ Priority = Not > Or > And (NOA)
○ And
■ True and True = True
■ T and F = F
■ F and F = F
■ F and T = F
○ Or
■ T or T = T
■ T or F = T
■ F or F = F
■ F or T = T
○ Not
■
○ Evaluating Left to Right
■ As long as there aren’t any syntax error, it can return an answer. If items are undefined
or don’t make sense, it does not evaluate
● Ex. True and not not not False or (1 + 3) >= Kaveh
True
● If statements
○ Only one “if” and “else”, and an unlimited amount of “elif” in the middle.
● Syllabus, PCRS, and general introductions
Lecture 02
● Terminology
○ 1+2
■ Operators = +
■ Operands = 1, 2
○ -3
■ Operator = -
■ Operand = 3
● Order of arithmetic precedence
○ ()
○ **
○ - (negative sign)
○ *, /, //, %
○ -, +
● Python documentation
○ Ex. round(number, ndigits=None)
■ Round = function
■ Number = first argument
■ Ndigits = second argument
■ = None
● If the second argument is provided, round will use the provided argument.
Otherwise, round will use the value None for the second argument
● Ex. round(42.54335, 2) = 42.54
● Ex. round(42.54335) = 43
● Ex. round(1234.5678, -2) = 1200.0
PCRS Jan 15, 2020
● Argument = values given
○ Ex. data = 3
data2 = 7.5
result = min(data, data2)
● Parameters = values not given
○ Ex. def f(data):
return data * 0.5
Lecture 03 Tues Jan 14, 2020
● Terminology
○ x=1
■ x has gets 1
■ x refers to the value of 1
■ x has a memory address of id1
■ memory address id1 is stored in variable
● Naming variables
○ Starts with a letter or underscore only
○ Contains only letters, digits, or underscores
○ Case sensitive
PCRS Weds Jan 15, 2020
● Function design recipe
○ Examples
○ Header
, ○ Description
○ Body
○ Test
Lecture 04 Thurs Jan 16, 2020
● Midterm expected for first week of february
● Worksheet “Function Design Recipe”
○ Strings always have quotes
○ print(‘yes \n no’)
yes
no
○ print(‘yes \’ no’)
■ yes ‘ no
○ repeat_word(‘smiles’, 0)
■ ‘’
Lecture 05 Tues Jan 21, 2020
● Python considers strings as values too, when it comes to strings
○ Dictionary order
■ ‘abs’ < ‘bsd’
True
■ ‘bs’ <= ‘asd’
False (python evaluates one character at a time, b with a, then s with s)
■ ‘B’ <= ‘a’
True (all lowercase letters come before all uppercase letters)
■ ‘’ < ‘b’
True (empty strings come before all lowercase and all uppercases)
● Priority
○ Arithmetic functions and amounts (greater, less than, etc.) are evaluated left to right
■ Ex. 1 + 1 == 2
True (better to write as (1 + 1) == 2)
● Boolean Operators
○ Priority = Not > Or > And (NOA)
○ And
■ True and True = True
■ T and F = F
■ F and F = F
■ F and T = F
○ Or
■ T or T = T
■ T or F = T
■ F or F = F
■ F or T = T
○ Not
■
○ Evaluating Left to Right
■ As long as there aren’t any syntax error, it can return an answer. If items are undefined
or don’t make sense, it does not evaluate
● Ex. True and not not not False or (1 + 3) >= Kaveh
True
● If statements
○ Only one “if” and “else”, and an unlimited amount of “elif” in the middle.