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.
You can type the weird symbols in Pseudocode that aren’t on the keyboard by typing a backslash, an abbreviation, and then hitting Alt + \ at the end. The abbreviations are:
\geq is ≥, but you can also write >=\leq is ≤, but you can also write <=\neq is ≠, but you can also write /=\leftarrow is ←, but you can also write <-\n in a string to jump to the next line. If your DISPLAY string ends in \n, there won’t be a space at the beginning of the next line.// before the part you want to comment.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.
Type the code below and see what it prints out.
a <- 17 b <- "xyz" DISPLAY(b) DISPLAY(a)
Using a REPEAT n TIMES loop, print this:
BEAT MALE BEAT MALE BEAT MALE BEAT MALE BEAT MALE BEAT MALE BEAT MALE
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.
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.
Write one REPEAT UNTIL(condition) loop for each line below that prints:
1 2 3 4 51 3 5 7 9 11 13 15 17 19 215 10 15 203 7 11 15 19 231 3 6 10 150 1 1 2 3 5 8 13 21 34 55 89Finish 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.