Lab 4 Predicates and Conditionals
- Review conditionals
- Practice writing predicates
- “Divide, Conquer, and Glue” (DCG): functions with conditionals
- Use CyberDuck to SFTP into your account on the
- On the server, navigate to the
- Download the
lab04folder to your Desktop (drag and drop it from the CyberDuck window)
Open Thonny and view the relevant
- Here is the worksheet as a google doc
- Open the document, then File -> Make a Copy.
- Then you can edit your copy with your answers.
Table of Contents
- Lab 4 Home
- Part 0: Warm up worksheet
- Part 1: Predicates and Functions
- Part 2: Conditionals
- Part 3: (OPTIONAL) Buzzfeed-style quiz
- Reference: Using Conditionals to Disable testing code
- What is a predicate, and how can you build a complex predicate out of
multiple simpler predicates?
Show AnswerA predicate is a function that always returns a boolean value. To build a complex predicate from simple ones, the complex predicate function should call the simple functions and combine their result values using boolean operators into a single boolean that it can return.
- What is the difference between writing a series of
ifstatements and a single
ifstatement with multiple
Show AnswerA series of if statements operate independently, and it's possible for more than one to trigger. A chain of if/elif statements guarantees that only the first statement whose condition is true will trigger, and others will be skipped even if their conditions are also true.