You are on page 1of 6

3.

WRITTEN RESPONSES

3 a.
3.a.i.
The purpose of the program is for the user to receive a fortune or a piece of advice when cracking open a
virtual fortune cookie.

3.a.ii.
The user can choose either to get a fortune or advice by clicking on a button. When the user clicks either
fortune button or advice button, the program begins a countdown of three seconds. After the countdown ends,
the fortune cookie is cracked and presents an open cookie with a small piece of paper of a fortune or advice.

3.a.iii.
The first type of input is the user clicking on the “advice” button or “fortune” button and the second is the user
answering “yes” or “no” to the question at the end checking if the user wants to play again. The output is a
text, a fortune or advice, displayed on the paper of the cracked fortune cookie.
3 b.
3.b.i.
3.b.ii.

3.b.iii.
In the images above, I captured two lists: “advice list” and “fortune list.” For this question, I focused on the list
named “fortune list.”

3.b.iv.
The list of strings stores different fortunes, which are randomly chosen to display on the screen at the end of
the game. Therefore, the list represents the possible outputs of the program.

3.b.v.
The “fortune list” is necessary in the program because it contains all of the fortunes or the possible outputs of
the program. Without using a list, the data in the list would be stored in single, individual variables, causing
the program to contain an unmanageable number of lines of code. For a list of n fortunes, we would have to
have n corresponding conditionals to generate each one without simply choosing randomly from a list.
3 c.
3.c.i.

3.c.ii.
3.c.iii.
The “display fortune” displays the three-second countdown after a user chooses advice or fortune. It
iteratively controls the order of the display of the three large numbers. It takes an integer called “number
input” (0 or 1) as a parameter. If the parameter is 0, it chooses a random item from the “fortune list.” However,
if 1, shown in the image, then it chooses a random item from the “advice list.” After the countdown, the
function can broadcast the fortune or piece of advice by storing the randomly chosen item into a variable
called “show end.”

3.c.iv.
The procedure has a parameter which is either 1 or 0 that will determine the display of either fortune or
advice. The procedure first chooses a “random number” from one to eight and assigns the number to a
random item of a list. Then, the procedure iterates in a form of a for loop to make the program display a three-
second countdown. The “if and else” statement checks if the parameter equals 1 or not. If the parameter is 1,
the procedure assigns the “show end” variable to a random item of the “advice list”, or else the procedure
will assign the “show end” variable to a random item of “fortune list”. Lastly, a message “crack” broadcasts
the random item of the list, which is either a fortune or advice.

3 d.
3.d.i.
First call:
The first call occurs when the user clicks fortune button. The procedure then checks if the argument passed
into the function is 1 or not to determine whether to display a random item from “advice list” or “fortune list.”

Second call:
The second call occurs when the user clicks advice button. The procedure then checks if the argument passed
into the function is 1 or not to determine whether to display a random item from “advice list” or “fortune list.”

3 d.ii.
Condition(s) tested by first call:
The if statement in “display fortune” checks if the input of the procedure is equal to 1 or not. The procedure
of the fortune button has an input of 0, so it assigns output to random fortune from “fortune list.”

Condition(s) tested by second call:


The if statement in “display fortune” checks if the input of the procedure is equal to 1 or not. The procedure
of the advice button has an input of 1, so it assigns output to a random advice from “advice list.”

3.d.iii.
Results of the first call:
The result of the first call is to display a random fortune from the “fortune list” onto the paper of the cracked
cookie, the output of the program.
Results of the second call:
The result of the second call is to display a random piece of advice from the “advice list” onto the paper of
the cracked cookie, the output of the program.

You might also like