CSE 115 Introduction to Computer Science I
Announcements Lab activites/lab exams submit regularly to autograder.cse.buffalo.edu
Announcements Lab activites/lab exams submit regularly to autograder.cse.buffalo.edu autograder enforces deadlines strictly
Announcements Lab activites/lab exams submit regularly to autograder.cse.buffalo.edu autograder enforces deadlines strictly lab activities and lab exams are INDIVIDUAL WORK
Announcements Lab activites/lab exams submit regularly to autograder.cse.buffalo.edu autograder enforces deadlines strictly lab activities and lab exams are INDIVIDUAL WORK we will address submission issues / week 1 glitches
Announcements Lab exams You have 55 minutes to complete your work. The second half of the recitation is reserved for other tasks/activities.
Road map Review control flow (sequencing, selection, repetition) sequencing selection
Review relational expressions Boolean expressions
Relational operators https://docs.python.org/3.7/library/stdtypes.html#comparisons Operation Meaning < strictly less than <= less than or equal > strictly greater than >= greater than or equal == equal!= not equal
Boolean operators https://docs.python.org/3.7/library/stdtypes.html#boolean-operationsand-or-not Operation Result Notes x or y if x is false, then y, else x (1) x and y if x is false, then x, else y (2) not x if x is false, then True, else (3) Notes: 1.This is a short-circuit operator, so it only evaluates the second argument if the first one is false. 2.This is a short-circuit operator, so it only evaluates the second argument if the first one is true. 3.not has a lower priority than non-boolean operators, so not a == b is interpreted as not (a == b), and a == not b is a syntax error.
Boolean expressions examples True or a and b x < y and y <= z x < y <= z Convenient, but unusual across languages.
Road map Review control flow (sequencing, selection, repetition) sequencing selection
SEQUENCING SELECTION REPETITION
Sequencing Statements in a block are executed in sequence. (i.e. one after the other, in the order written) This is what we've seen so far.
Selection One of a set of instructions is executed, based on the outcome of a decision. Exactly one of many possible branches is followed.
Repetition A block is repeated several times, based on the outcome of a decision. Also called looping.
visualizing We use "flow charts" to help visualize the flow of control through a program, when appropriate. SIMPLE STATEMENT DECISION arrow depicts FLOW OF CONTROL
visualizing sequences a = 12 b = 2 * a + 1 c = b - a a = 12 b = 2 * a + 1 c = b - a
visualizing sequences Control starts at the arrow whose origin is not connected to a box a = 12 b = 2 * a + 1 c = b - a a = 12 b = 2 * a + 1 c = b - a
visualizing sequences a = 12 b = 2 * a + 1 c = b - a a = 12 b = 2 * a + 1 c = b - a Control ends at the arrow whose terminus is not connected to a box
Selection: the if statement Here's an example of an if statement: if x < y :
Selection: the if statement 'if' is a keyword if x < y :
Selection: the if statement 'x < y' is a Boolean expression if x < y :
Selection: the if statement : is a delimiter if x < y :
Selection: the if statement What follows the ':' is a block (sequence) of statements. if x < y : Recall Python refers to the a block of statements as a "suite".
visualizing selection (if) if x < y : x < y True
visualizing selection (if) if x < y : x < y True
visualizing selection (if) if x < y : x < y True
visualizing selection (if) if x < y : x < y True
visualizing selection (if-else) if x < y : else : x < y True
visualizing selection (if-else) if x < y : else : x < y True
visualizing selection (if-else) if x < y : else : x < y True
visualizing selection (if-else) if x < y : else : x < y True
visualizing selection (if-else) if x < y : else : x < y True
visualizing selection (if-elif-else) if x < y : elif x == y : z = 0 else : x < y x == y True True z = 0
visualizing selection (if-elif-else) if x < y : elif x == y : z = 0 else : x < y x == y True True z = 0
visualizing selection (if-elif-else) if x < y : elif x == y : z = 0 else : x < y x == y True True z = 0
visualizing selection (if-elif-else) if x < y : elif x == y : z = 0 else : x < y x == y True True z = 0
visualizing selection (if-elif-else) if x < y : elif x == y : z = 0 else : x < y x == y True True z = 0