1.1.7 traversing turtles

0.0(0)
studied byStudied by 11 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

12 Terms

1
New cards

list

An ordered collection of items or values. For example, [value1, value2, value3, …] describes a list where value1 is the first element, value 2 is the second element, value 3 is the third element, and so on. 


2
New cards

array

An ordered collection of elements of the same type.  


3
New cards

literal

A literal is a fixed value in source code, such as 5 or "hello".  


4
New cards

list element

An individual value in a list that is assigned a unique index.  


5
New cards

loop variable

In each iteration step, a variable set to a value in a sequence or other data collection.  


6
New cards

lists concept


  • We use these to group data types with a construct known as a list. 

  • Some other programming languages refer to a list as an array. 

    • ANYTHING CAN BE GROUPED TOGETHER IN A LIST

      • Numbers, words, fruits, animals, colors. 

How college board uses the following to represent assigning values to a list 

aList [value1, value2, value3...]

This creates a new list that contains the values value1, value2, value3, and … at indices 1, 2, 3, and … respectively and assigns it to aList.

aList ← []

Creates a new empty list and assigns it to aList.

You can also copy a list to another list. 

aList bList

This assigns a copy of the list bList to the list aList. For example, if bList contains [20, 40, 60], then aList will also contain [20, 40, 60] after the assignment.


7
New cards

how do you add an e;ement to the end of a list?

  • You can do this using the append method. 

  • The College Board uses APPEND(aList, value)  to represent adding items to a list.

8
New cards

how do you get the last item that was placed into the list and remove it, much like you would grab the top item out of a basket or bag?

  • You use the pop method

  • It removes the last element of the list and assigns it to a variable. 

9
New cards

how do you repeat a task for each item in the list?

  • By using a for loop. 

    • A for loop retrieves each element from the list and assigns it to the loop variable. 

      • Using the loop variable, you can have the program execute the same set of statements for each element. In effect, the loop variable can be assigned to each element of a list on each interaction of the list. 

      • The College Board uses the following notation to represent a for loop:

      • FOR EACH item IN aList

      • {

      •     <block of statements>

      • }

10
New cards
  • Assume you have a list of numbers such as a_list= [1,2,3,4,5]

  • Which of the following statements will add a new number to the list? 

    • a_list=a_list +6

    • a_list=(6)

    • a_list.append(6)

    • a_list.add(6)

C

11
New cards
  • Assume that you have a list of numbers such as a_list=[1,2,3,4,5]

  • Select the for statement that iterates through the list. 

    • For num in a_list: 

    • For (num,a_list): 

    • For each (num in a_list): 

    • For each (num,a_list):

A

12
New cards
  • Assume that you have a list of numbers such as a_list= [1,2,3,4,5]

  • What would  the value of num be after the following code? 

  • num=a_list.pop()

  • num=a_list.pop()

    • 1

    • 2

    • 4

    • 5

C