Lab04: Lists + HOFs

Due at: Monday July 6th, 2359 hrs

Lab 4: Lists + HOFs

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 course.

Submitting:

You will need to fill in the blocks under “Lab 4: Lists + HOFs” 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.

Please use the “run autograder” block for testing. Do not use the other predicate blocks found in the autograder block sections.

Objectives:

Previously, you’ve explored lists, a collection of elements that can be accessed by their position. By the end of the lab, you will:

  • Understand and implement lists into your code
  • Practice using high order functions in your code
  • Understand the use and importance of high order functions

Required Blocks:

  • Block 1: acronym of list (wordlist)
  • Block 2: acronym keep only capitals (input)
  • Block 3: exaggerate (input)
  • Block 4: expand (input)

Important Topics in 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: acronym of list (wordlist)

Objective:

  • Create a reporter block that reports the first letter of each string, all joined together.

Notes:

  • You should not use map or combine when creating your block
  • You must use hyperblocks! Use of HOFs and iterative blocks will fail the tests!
  • Try the join block

Inputs:

  • wordlist: List

Output:

  • Reports: Text

Examples:

  • example with input "computer science" outputs "cs"
  • example with input "data structures" outputs "ds"

Block 2: acronym keep only capitals (input)

Objective:

  • Create a reporter block that reports the first letter of each string with a capital letter in the front, all joined together.

Inputs:

  • input: Text
    • usually a sentence or phrase

Output:

  • Reports: Text

Examples:

  • example with input "University of California Berkeley" outputs "UCB"
  • example with input "The Beauty and Joy of Computing" outputs "TBJC"

Block 3: exaggerate (input)

Objective:

  • Write a reporter exaggerate that takes a sentence as input and reports an exaggerated version.
  • It should replace “good” with “great,” “bad” with “terrible,” and “like” with “love”
  • It should replace every number with twice the number.
  • Inputs:
  • input: Text
    • usually a sentence or phrase

Output:

  • Reports: Text

Examples:

  • example showing text transformation with word replacements
  • example showing text transformation with number doubling
  • example showing combined word and number transformations

Block 4: expand (input)

Objective:

  • Write an expand reporter that takes a sentence as input, and reports a sentence that’s the same except that each number in the input is replaced by that many copies of the following word

Notes:

  • If the last word is a number, add the number unmodified.

Inputs:

  • input: Text
    • usually a sentence or phrase

Output:

  • Reports: Text

Examples:

  • example showing number expansion with following words
  • example showing multiple number expansions
  • example showing edge case with number at end

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.