cse 115
play

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


  1. CSE 115 Introduction to Computer Science I

  2. Announcements Lab activites/Lab exams submit regularly to autograder.cse.bu fg alo.edu

  3. Announcements Lab activites/Lab exams submit regularly to autograder.cse.bu fg alo.edu autograder enforces deadlines strictly

  4. Announcements Lab activites/Lab exams submit regularly to autograder.cse.bu fg alo.edu autograder enforces deadlines strictly lab activities and lab exams are INDIVIDUAL WORK

  5. Announcements Lab activites/Lab exams submit regularly to autograder.cse.bu fg alo.edu autograder enforces deadlines strictly lab activities and lab exams are INDIVIDUAL WORK we will address submission issues / week 1 glitches

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

  7. Road map ▶︎ Review ◀ control flow (sequencing, selection, repetition) sequencing selection

  8. Review relational expressions Boolean expressions

  9. 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 !=

  10. Boolean operators https://docs.python.org/3.7/library/stdtypes.html#boolean-operations- and-or-not Operation Result Notes if x is false, then y, else x (1) x or y if x is false, then x, else y (2) x and y if x is false, then True , else False (3) not x 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.

  11. Boolean expressions examples True or False a and b x < y and y <= z Convenient, but unusual x < y <= z across languages.

  12. Road map Review ▶︎ control flow (sequencing, selection, repetition) ◀ sequencing selection

  13. Control flow SEQUENCING SELECTION REPETITION

  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.

  15. Control flow Selection One of a set of instructions is executed, based on the outcome of a decision. Exactly one of many possible branches is followed.

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

  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

  18. Control flow visualizing sequences a = 12 a = 12 b = 2 * a + 1 c = b - a b = 2 * a + 1 c = b - a

  19. Control flow Control starts at the visualizing sequences arrow whose origin is not connected to a box a = 12 a = 12 b = 2 * a + 1 c = b - a b = 2 * a + 1 c = b - a

  20. Control flow visualizing sequences a = 12 a = 12 b = 2 * a + 1 c = b - a b = 2 * a + 1 c = b - a Control ends at the arrow whose terminus is not connected to a box

  21. Control flow Selection: the if statement Here's an example of an if statement: if x < y : z = y

  22. Control flow Selection: the if statement 'if' is a keyword if x < y : z = y

  23. Control flow Selection: the if statement 'x < y' is a Boolean expression if x < y : z = y

  24. Control flow Selection: the if statement : is a delimiter if x < y : z = y

  25. Control flow Selection: the if statement What follows the ':' is a block (sequence) of statements. if x < y : Recall z = y Python refers to the a block of statements as a "suite".

  26. Control flow x = 12 visualizing selection (if) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False a = (x + y) - z a = (x + y) - z

  27. Control flow x = 12 visualizing selection (if) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False a = (x + y) - z a = (x + y) - z

  28. Control flow x = 12 visualizing selection (if) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False a = (x + y) - z a = (x + y) - z

  29. Control flow x = 12 visualizing selection (if) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False a = (x + y) - z a = (x + y) - z

  30. Control flow x = 12 visualizing selection (if-else) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False else : z = x z = x a = (x + y) - z a = (x + y) - z

  31. Control flow x = 12 visualizing selection (if-else) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False else : z = x z = x a = (x + y) - z a = (x + y) - z

  32. Control flow x = 12 visualizing selection (if-else) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False else : z = x z = x a = (x + y) - z a = (x + y) - z

  33. Control flow x = 12 visualizing selection (if-else) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False else : z = x z = x a = (x + y) - z a = (x + y) - z

  34. Control flow x = 12 visualizing selection (if-else) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False else : z = x z = x a = (x + y) - z a = (x + y) - z

  35. Control flow x = 12 visualizing selection (if-elif-else) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False elif x == y : z = 0 True z = 0 x == y else : z = x False a = (x + y) - z z = x a = (x + y) - z

  36. Control flow x = 12 visualizing selection (if-elif-else) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False elif x == y : z = 0 True z = 0 x == y else : z = x False a = (x + y) - z z = x a = (x + y) - z

  37. Control flow x = 12 visualizing selection (if-elif-else) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False elif x == y : z = 0 True z = 0 x == y else : z = x False a = (x + y) - z z = x a = (x + y) - z

  38. Control flow x = 12 visualizing selection (if-elif-else) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False elif x == y : z = 0 True z = 0 x == y else : z = x False a = (x + y) - z z = x a = (x + y) - z

  39. Control flow x = 12 visualizing selection (if-elif-else) y = 14 x = 12 y = 14 True if x < y : x < y z = y z = y False elif x == y : z = 0 True z = 0 x == y else : z = x False a = (x + y) - z z = x a = (x + y) - z

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend