Lab 03: Conditionals, Reporters, & Abstraction

Due at: Wednesday September 10th, 11:59PM

Lab 3: Conditionals, Reporters, & Abstraction

Instructions

This worksheet serves as a guide and set of instructions to complete Lab 3. All material was sourced from the CS10 version of The Beauty and Joy of Computing (BJC) course.

  • You must use the starter file, found here to get credit for the lab.
  • Additionally, here is the workbook that you can read through for further context and additional (non-required) material.

Submitting

You will need to fill in the blocks under “Lab 3: Conditionals, Reporters, & Abstraction” and submit this to Gradescope.

  • To receive full credit, you must complete the required blocks, and those blocks must pass all tests from the Gradescope autograder.
  • For instructions on how to submit labs to Gradescope, please see this page.

Please note: you must use the starter file above, and you must not edit the name of any required blocks. Failing to do either will result in autograder failure.

Objectives

So far, you’ve practiced writing scripts that carry out short sequences of commands (they run every block, in order). In this lab you will explore conditionals for more complex behavior. By the end of the lab, you will:

  • Implement conditional statements in your code.
  • Practice writing and reading functions with booleans and boolean operators.
  • Understand the use of reporter functions and their outcomes.

Required Blocks

Important Topics mentioned in the Workbook

For better understanding of the lab we highly recommend going through these workbook pages! Topics that are important but not required for this lab will be indicated with an asterisk **. These topics are best reviewed in order and as you complete the lab.


Block 1: Traffic signal (color)

Objective

  • Create a reporter block that, when given a traffic light color, reports the appropriate action (see below).

Inputs

  • color = any text
    Any text can be typed, but the autograder will test the three traffic light colors: Red, Green, Yellow.

Output

  • Reports Text. Case-sensitive mappings:
    • Input: Green → Output: Go
    • Input: Red → Output: Stop
    • Input: Yellow → Output: Yield

Examples

  • example of traffic signal reporter 'Yellow' with output 'Yield'
  • example of traffic signal reporter 'Red' with output 'Stop'
  • example of failed traffic signal reporter 'Cheese' with output 'did not report'

Block 2: letter grade (number)

Objective

  • Create a reporter block that, when given a percentage, says the associated letter grade.
    Example: letter grade (74) should say C.

Standardized Letter Grades

  • A: 90–100
  • B: 80–89.99
  • C: 70–79.99
  • D: 60–69.99
  • F: < 60
    Note: the autograder is sensitive to decimals and should work for all non-negative numbers (e.g., 89.99123123).

Inputs

  • number = any number
    You may assume users will input a non-negative number ≤ 100.

Output

  • Reports Text (case-sensitive, no extra spaces or quotes).

Examples

  • example of letter grade reporter '89.999' with output 'B'
  • example of letter grade reporter '70' with output 'C'
  • example of letter grade reporter '2' with output 'F'

Block 3: is (num1) between (num2) and (num3)

Objective

  • Create a predicate block that determines if a number is between two other numbers.
    Return true if the first number is between the other two or equal to either boundary.

Notes

  • num1, num2, and num3 can be the same numbers.
  • num2 and num3 may be in any order (e.g., num3 can be less than num2).

Inputs

  • num1, num2, num3 = any numbers.

Output

  • Reports a boolean (true or false).

Examples

  • example of is '3' between '1' and '5' and reports 'True'
  • example of is '9' between '1' and '5' and reports 'False'
  • example of is '88' between '36' and '-5' and reports 'False'
  • example of is '4' between '4' and '4' and reports 'True'

Block 4: sum of two smallest (num1) and (num2) and (num3)

Objective

  • Edit a reporter block named “sum of two smallest” that takes three numbers and reports the sum of the two smallest.

Notes

  • If the two greatest numbers are the same, report the smallest plus either of the two equal numbers.
  • If all three numbers are the same, report the sum of any two of them.

Inputs

  • num1, num2, num3 = any numbers.

Output

  • Reports a Number (the sum of the two smallest inputs).

Examples

  • example of sum of two smallest '2' and '5' and '5' and reports '7'
  • example of sum of two smallest '9' and '9' and '9' and reports '18'
  • example of sum of two smallest '1' and '12' and '2' and reports '3'

Hint: Look at the max block. How does it work?


You can always check the validity of your solutions by using the local autograder. Remember to submit on Gradescope and complete the conceptual portion!

Submission

You may submit more than once before the deadline; only the final submission will be graded. It is your responsibility to check that the autograder on Gradescope runs as expected after you upload your submission.