Playing with Pseudocode

I’ve created a way for you to practice with pseudocode.

Open DrRacket. It looks like in the bottom menu bar.

Once it’s open, type

#lang apcsp-pseudocode

on the top line of the top window and hit the Run button near the top-right of the window.

Now you can type in pseudocode and run it. (Make sure you leave the # line at the top, though.)

There are a couple of differences between real pseudocode and this.

Note: the pseudocode doesn’t care about blank lines, so you should probably put a line or two between each problem. You can put DISPLAY("\n") to skip a line in your code to separate the output. DISPLAY("\n\n") would skip two lines.

  1. Type the code below and see what it prints out.

    a <- 17
    b <- "xyz"
    DISPLAY(b)
    DISPLAY(a)
  2. Using a REPEAT n TIMES loop, print this:

    BEAT MALE
    BEAT MALE
    BEAT MALE
    BEAT MALE
    BEAT MALE
    BEAT MALE
    BEAT MALE
  3. Write a program that asks for someone’s name and age and prints out

    Hello, <their name>
    You're <their age> years old.

    So, your whole program should do something like

    What's your name? Taylor Swift
    How old are you? 35
    
    Hello, Taylor Swift
    You're 35 years old.
  4. Finish this procedure that takes a list parameter and prints each element of the list on a separate line.

    PROCEDURE printEach(myList)
    {
      <your code here>
    }
    printEach(["a", 5, true])
    printEach([3, 2, 1, "blastoff"])

    should print

    a
    5
    true
    3
    2
    1
    blastoff

    once you’ve filled in your code.

  5. Write one REPEAT UNTIL(condition) loop for each line below that prints:

    1. 1 2 3 4 5
    2. 1 3 5 7 9 11 13 15 17 19 21
    3. 5 10 15 20
    4. 3 7 11 15 19 23
    5. 1 3 6 10 15
      (You’ll need two variables for this one.)
    6. 0 1 1 2 3 5 8 13 21 34 55 89
      (This is a challenge problem. You’ll need at least two variables for this one.)
  6. Finish this procedure. It should return the ticket price to a movie based on a person’s age: under 13 = $10, 13-54 = $15, 55 and over = $12

    PROCEDURE ticketPrice(age)
    {
      <your code here, use RETURN>
    }
    DISPLAY(ticketPrice(10))
    DISPLAY(ticketPrice(16))
    DISPLAY(ticketPrice(72))

    should print

    10 15 12

    when you’ve filled in your code.