CSE 115 Introduction to Computer Science I Announcements Lab - - PowerPoint PPT Presentation

cse 115
SMART_READER_LITE
LIVE PREVIEW

CSE 115 Introduction to Computer Science I Announcements Lab - - PowerPoint PPT Presentation

CSE 115 Introduction to Computer Science I Announcements Lab activites/Lab exams submit regularly to autograder.cse.bu fg alo.edu Announcements Lab activites/Lab exams submit regularly to autograder.cse.bu fg alo.edu autograder enforces


slide-1
SLIDE 1

CSE 115

Introduction to Computer Science I

slide-2
SLIDE 2

Announcements

Lab activites/Lab exams

submit regularly to autograder.cse.bufgalo.edu

slide-3
SLIDE 3

Announcements

Lab activites/Lab exams

submit regularly to autograder.cse.bufgalo.edu autograder enforces deadlines strictly

slide-4
SLIDE 4

Announcements

Lab activites/Lab exams

submit regularly to autograder.cse.bufgalo.edu autograder enforces deadlines strictly lab activities and lab exams are INDIVIDUAL WORK

slide-5
SLIDE 5

Announcements

Lab activites/Lab exams

submit regularly to autograder.cse.bufgalo.edu autograder enforces deadlines strictly lab activities and lab exams are INDIVIDUAL WORK we will address submission issues / week 1 glitches

slide-6
SLIDE 6

Announcements

Lab exams

You have 55 minutes to complete your work. The second half of the recitation is reserved for other tasks/activities.

slide-7
SLIDE 7

Road map

▶︎ Review ◀ control flow (sequencing, selection, repetition) sequencing selection

slide-8
SLIDE 8

Review

relational expressions Boolean expressions

slide-9
SLIDE 9

Operation Meaning

< strictly less than <= less than or equal > strictly greater than >= greater than or equal == equal != not equal

Relational operators

https://docs.python.org/3.7/library/stdtypes.html#comparisons

slide-10
SLIDE 10

Boolean operators

https://docs.python.org/3.7/library/stdtypes.html#boolean-operations- and-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 False (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.

slide-11
SLIDE 11

Boolean expressions

examples

True or False a and b x < y and y <= z x < y <= z

Convenient, but unusual across languages.

slide-12
SLIDE 12

Road map

Review ▶︎ control flow (sequencing, selection, repetition) ◀ sequencing selection

slide-13
SLIDE 13

Control flow

SEQUENCING SELECTION REPETITION

slide-14
SLIDE 14

Control flow

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.

slide-15
SLIDE 15

Control flow

Selection

One of a set of instructions is executed, based on the

  • utcome of a decision.

Exactly one of many possible branches is followed.

slide-16
SLIDE 16

Control flow

Repetition

A block is repeated several times, based on the outcome of a decision. Also called looping.

slide-17
SLIDE 17

Control flow

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

slide-18
SLIDE 18

Control flow

visualizing sequences

a = 12 b = 2 * a + 1 c = b - a a = 12 b = 2 * a + 1 c = b - a

slide-19
SLIDE 19

Control flow

visualizing sequences

a = 12 b = 2 * a + 1 c = b - a a = 12 b = 2 * a + 1 c = b - a

Control starts at the arrow whose origin is not connected to a box

slide-20
SLIDE 20

Control flow

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

slide-21
SLIDE 21

Control flow

Selection: the if statement

Here's an example of an if statement: if x < y : z = y

slide-22
SLIDE 22

Control flow

Selection: the if statement

'if' is a keyword if x < y : z = y

slide-23
SLIDE 23

Control flow

Selection: the if statement

'x < y' is a Boolean expression if x < y : z = y

slide-24
SLIDE 24

Control flow

Selection: the if statement

if x < y : z = y : is a delimiter

slide-25
SLIDE 25

Control flow

Selection: the if statement

if x < y : z = y What follows the ':' is a block (sequence) of statements.

Recall Python refers to the a block of statements as a "suite".

slide-26
SLIDE 26

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

Control flow

visualizing selection (if)

x = 12 y = 14 if x < y : z = y a = (x + y) - z

slide-27
SLIDE 27

x = 12 y = 14 if x < y : z = y a = (x + y) - z x = 12 y = 14 z = y a = (x + y) - z x < y

True False

Control flow

visualizing selection (if)

slide-28
SLIDE 28

z = y x = 12 y = 14 if x < y : z = y a = (x + y) - z x = 12 y = 14 a = (x + y) - z x < y

True False

Control flow

visualizing selection (if)

slide-29
SLIDE 29

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

Control flow

visualizing selection (if)

x = 12 y = 14 if x < y : z = y a = (x + y) - z

slide-30
SLIDE 30

Control flow

visualizing selection (if-else)

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

x = 12 y = 14 if x < y : z = y else : z = x a = (x + y) - z z = x

slide-31
SLIDE 31

Control flow

visualizing selection (if-else)

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

x = 12 y = 14 if x < y : z = y else : z = x a = (x + y) - z z = x

slide-32
SLIDE 32

Control flow

visualizing selection (if-else)

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

x = 12 y = 14 if x < y : z = y else : z = x a = (x + y) - z z = x

slide-33
SLIDE 33

Control flow

visualizing selection (if-else)

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

x = 12 y = 14 if x < y : z = y else : z = x a = (x + y) - z z = x

slide-34
SLIDE 34

Control flow

visualizing selection (if-else)

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

x = 12 y = 14 if x < y : z = y else : z = x a = (x + y) - z z = x

slide-35
SLIDE 35

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

x == y

Control flow

visualizing selection (if-elif-else)

x = 12 y = 14 if x < y : z = y elif x == y : z = 0 else : z = x a = (x + y) - z z = 0

True False

z = x

slide-36
SLIDE 36

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

x == y

Control flow

visualizing selection (if-elif-else)

x = 12 y = 14 if x < y : z = y elif x == y : z = 0 else : z = x a = (x + y) - z z = 0

True False

z = x

slide-37
SLIDE 37

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

x == y

Control flow

visualizing selection (if-elif-else)

x = 12 y = 14 if x < y : z = y elif x == y : z = 0 else : z = x a = (x + y) - z z = 0

True False

z = x

slide-38
SLIDE 38

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

x == y

Control flow

visualizing selection (if-elif-else)

x = 12 y = 14 if x < y : z = y elif x == y : z = 0 else : z = x a = (x + y) - z z = 0

True False

z = x

slide-39
SLIDE 39

x = 12 y = 14 z = y a = (x + y) - z x < y

True False

x == y

Control flow

visualizing selection (if-elif-else)

x = 12 y = 14 if x < y : z = y elif x == y : z = 0 else : z = x a = (x + y) - z z = 0

True False

z = x