15. Conditionals

Making choices in Racket using ‘cond’.

See slides for introductory material.

Exercise Notes / Advice

  • 15.3.4: The first input is the candidate for whom you are counting votes. (For example “Clinton”.) The next four inputs are votes cast for a person. (For example “Trump” “Clinton” “Sanders” “Trump”.) You are supposed to return the number of votes for the candidate from the first input. (For example: 1 in this case.)

  • 15.3.7: Keep using build-image not build3-image.

Assignments

Assignment 15.A

Read the first three sections of Chapter 15. Do Exercises 15.3.{3,4}. These are on PDF page 223.

Assignment 15.B

Exercises 15.3.{5-8}.

Assignment 15.C

Exercises 15.5.{1,2,3,4,5}. These begin on PDF page 229.

Assignment 15.D

Read 15.6 (“Unnecessary conditionals”). Skip Section 15.7.

Do Exercises 15.8.{2,3,5}. Exercise 15.5.6. These begin on the bottom of PDF page 238.

Images

See the build-image tutorial. Use that to do 15.3.3 and 15.3.{7-10}. Do not use build3-image even though the book says to use it. The build-image function is better.

Practice Quiz

Get ready by doing an old Chapter 15 quiz.

All

  • 15. Slides
  • Day 1 Exercises

  • 15. Cond Patterns
  • Patterns with conditionals and build-image.

  • 15. Another Challenge
  • A beautiful image made with a conditional in build-image.

  • 15. Graphing Review
  • A review of graphing with people and computer coordinates.

  • 15. Heatmap
  • Using cond to create a multi-segment heat map. Applying it to the graphing review.

  • 15. Heatmap with Contours
  • Color pixels based on values of a function. Put contour lines every 50 values.

  • 15. Practice All
  • Do all of this work in a single Racket file. You need to turn this assignment in on classroom. You may attach your solution file or copy and paste the code as a private comment and mark the assignment complete. Read Section 15.6 (Unnecessary conditionals) to review how to simplify. (PDF page 230ff.) Note to book readers: I disagree with the author about section 15.7 (nested conditionals) so I suggest not reading it.

  • 15. Practice Quiz
  • Practice quiz, adapted from a previous year.


15. Slides

Day 1 Exercises

15. Cond Patterns

Patterns with conditionals and build-image.

15. Another Challenge

A beautiful image made with a conditional in build-image.

15. Graphing Review

A review of graphing with people and computer coordinates.

15. Heatmap

Using cond to create a multi-segment heat map. Applying it to the graphing review.

15. Heatmap with Contours

Color pixels based on values of a function. Put contour lines every 50 values.

15. Practice All

15. Practice Quiz

Practice quiz, adapted from a previous year.