COMP 110 QUIZ 02 V2

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

1/24

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.

25 Terms

1
New cards
.append()
Adds an item to the end of the list. It modifies the list in place.
2
New cards
.pop(index)
Removes and returns the element at the given index.
3
New cards
len() for a list
The number of elements currently in the list.
4
New cards
while loop
A control flow structure that repeatedly executes a block of code as long as its condition evaluates to True.
5
New cards
repeat block in a while loop
The indented code that runs over and over while the condition is True.
6
New cards
What is the purpose of a while loop?
To repeatedly execute code as long as a condition is True.
7
New cards
What causes an infinite loop?
A loop condition that never becomes False.
8
New cards
How do you prevent an infinite loop?
Update a variable involved in the condition each iteration to move toward False.
9
New cards

What is variable declaration/definition?

Connecting a name to a type and reserving space in memory.

10
New cards
What is variable assignment?
Giving a value to a variable name.
11
New cards
What is variable initialization?
The first time a variable is assigned a value.
12
New cards
What is variable access?
Using a variable's value in an expression.
13
New cards
What error occurs when accessing an uninitialized variable inside a function?
UnboundLocalError
14
New cards
What error occurs if a variable was never declared?
NameError
15
New cards
In x = y, which side is evaluated first?
The right-hand side (y) is evaluated, then assigned to x.
16
New cards
What should the sum_to_zero(i) function do?
Use a while loop to add numbers from 0 to i and return the total.
17
New cards
What should the sum_ints(my_list) function do?
Use a loop to sum all numbers in my_list and return the result.
18
New cards
How do you declare a list of integers?
my_list: list[int].
19
New cards
How do you create an empty list?
With [] or list().
20
New cards
How do you access an item in a list?
Use subscription notation: my_list[index].
21
New cards
How do you assign a new value to a specific index in a list?
my_list[index] = new_value.
22
New cards
What does .append(item) do?
Adds item to the end of the list.
23
New cards
What does .pop(index) do?
Removes and returns the item at that index.
24
New cards
What does del my_list[index] do?
Deletes the item at that index without returning it.
25
New cards
What does len(my_list) return?
The number of items currently in the list.