Lab02: Conditionals, Reporters, & Abstraction
Lab 2: Conditionals, Reporters, & Abstraction
Instructions:
This worksheet serves as a guide and set of instructions to complete lab 2. All material was sourced from the CS10 version of The Beauty and Joy of Computing 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.
- All material was sourced from the CS10 version of The Beauty and Joy of Computing course.
Submitting:
You will need to fill in the blocks under “Lab 2: Conditionals, Reporters, & Abstraction” and submit this to Gradescope.
- To receive full credit, you will need to complete the required blocks, and the required blocks must pass all tests from the autograder in Gradescope.
- For instructions on how to submit to labs to Gradescope, please see this page.
Please note, you must use the starter file, and you must NOT edit the name of any of the required blocks. Failing to do either for these will result in the autograder failing.
Objectives:
So far, you’ve practiced writing scripts that carry out short sequences of commands. These scripts will run every single one of their blocks, no matter how. In this lab you will explore a new level of complexity with the idea of conditionals. By the end of the lab, you will:
- Implement conditional statements into your code
- Practice writing and reading functions with booleans and boolean operators
- Understand the use of reporter functions and their outcomes
Required Blocks:
- Block 1: traffic signal (color)
- Block 2: letter grade (number)
- Block 3: is (num1) between (num2) and (num3)
- Block 4: sum of two smallest (num1) and (num2) and (num3)
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.
- Introduction: why do we need conditionals?
- If and If-else
- More Complex Boolean Expressions**
- Predicates
- The Max block
Block 1: Traffic signal (color)
Objective:
- Create a reporter block that when inputted a traffic light color it makes the sprite report the appropriate action (see below)
Inputs:
- color = any text
- This variable takes in any text input.
- Any text can be typed, but for the autograder we will be testing the three traffic light colors: Red, Green, Yellow
Output:
- Reports: Text
- The following inputs and outputs need to be case sensitive to pass the autograder
- Input: Green –> Output: Go
- Input: Red –> Output: Stop
- Input: Yellow –> Output: Yield
Examples:
Block 2: letter grade (number)
Objective:
- Create a reporter block that when inputted percentage, makes the sprite say the associated letter grade. For example, letter grade (74) should say “C.”
- Standardized Letter Grade
- A: 90-100, B: 80-89.99, C 70-79.99, D: 60-69.99, F < 60
- Note that the autograder is sensitive to decimals and should work for all non negative numbers. Ex. 89.99123123
Inputs:
- number = any number
- This variable takes in any number. However we can assume that the user will input a non negative, whole number 100 or less.
Output:
- Reports: Text
- The following outputs need to be case sensitive to pass the autograder. No spaces, no quotes “”
- A: 90-100, B: 80-89.99, C: 70-89.99, D: 60-69.99, F: < 60
Examples:
Block 3: is (num1) between (num2) and (num3)
Objective:
- Create a predicate block that determines if a number is between two other numbers. The block should return true if the first number is between the two numbers or if it is equal to either of the numbers.
- Note: num1, num2, num3 can be the same numbers
- Num2 and num3 can be non numerical order, that is num3 can be less than num2
Inputs:
- num1, num2, num3 = any number
- This variable takes in any and all numbers
Output:
- Reports a boolean (True or False)
Examples:
[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 as inputs, and reports the sum of the two smallest
- If two of the greatest numbers are the same the block should report the smallest and any of the two
- If three numbers are the same, the block should report the sum of two of the numbers
Inputs:
- num1, num2, num3 = any number
- This variable takes in any and all numbers
Output:
- Reports: Num (the sum of the smallest two numbers)
Examples:
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!