
pause all
stuff lost with optionalization of mandala design and also to update debugging page. --MF, 7/5/19On this page, you will begin to develop a quiz app by creating an abstract data type to pair the questions with their answers.
You'll use a list to store your quiz items in a variable. You could just put all the questions and their answers in a list like this and then use to retrieve each question and each answer using its index.
A sublist is a list as an item of another list.
Instead, you can use a sublist for each question/answer pair. Then you could choose just one of those lists at a time to work with.
But with nested lists (lists with sublists) it can be hard to keep track of the input numbers for item of
, so a better way is to use abstraction to organize the quiz items.
This abstraction just hides the list
and item of
blocks, so it isn't complicated to build, but it can make your code much easier to write, read, and debug.
quiz item
has to think only about questions and answers, not about list indices.
The word "abstract" is often used casually to mean something harder to understand or more complex, but in computer science, its meaning is almost the opposite. ADTs are things that you, the programmer, create to make your program easier for you and others to read, debug, and improve.
quiz item
abstract data type.
quiz item
abstract data type (both the constructor and the two selectors).Your selectors expect a quiz item, i.e., a list, as input. You can make your blocks show what type of data they expect. It's not necessary in Snap! but, like assigning a color to a block, it can be a helpful reminder of what the block does and what type of input it expects. You've already seen input slots of several shapes, indicating different expected data types.
In the Block Editor while creating a selector, click on a plus sign to enter an input name. Then...
Imagine you make a variable capitals and use set
to give this list of lists a name:
Which of the following statements are true?
Choose all that apply.