Unit 4
4.5
Unit 5
5.5
Unit 6
100

List all Binary Relational Operators

Equality: ==

Inequality: !=

Less than: <

Less than or equal to: <=

Greater than: >

Greater than or equal to: >=

100

What is an index?

The position of a token in an iterable sequence

string_one = "Hey"

string_one[2] == 'y'

string_one[len(string_one) - 1] == ?

string_one[len(string_one)] == ?

100

How do you open a file without manually having to close it?

with open(filename) as file:

     ...

100

What does next(file) do?

Skips the header of the file, ignoring the first line of the file.

100

What is the difference between a strip and split?

Strip returns the string with removed whitespaces.

"   hello    ".strip() == "hello"

Split returns a sequence of tokens created using a given delimiter

"hello world".split(" ") == ["hello", "world"]

200

Each time a loop executes the block of statements in its body is known as what?

An iteration

200

What is the DRY principle and what is the advantage of utilizing it?

Don't Repeat Yourself

Avoids repetitive code

200
What is the difference between an absolute path and a relative path?

An absolute path refers to the same location in a file system relative to the root directory. (C:/Users/ron/SoftDevI/a_file.txt)

A relative path points to a specific location in a file system relative to the current directory you are working on. (SoftDevI/a_file.txt)

200

When using try/except statements, when will the except block be executed?

Whenever an exception occurs inside the try block (statement).

200

Describe the linear search algorithm.

Beginning at index 0, compare the value at each index to the target. 

If the value matches the target, return the index. 

If you make it all the way through the array, without finding the target, return None.

300

How do you determine the length of a string?
If a string has a length of k elements, can you access the kth character?

len(str)

No, you cannot access the kth element. You can access the kth-1 element.

300

WILDCARD

+300

300

If you are importing a Python file, that calls the main function, into a test file, what should you add at the end of the Python file being tested?

if __name__ == "__main__":

    main()

300

WILDCARD

-300

300

When performing a binary search on an array, does the array have to be sorted? What about when performing a linear search?

The array must be sorted when performing a binary search. The array does not have to be sorted when performing a linear search.

400

When would you use each of the following: break, continue, pass

Use a break to get out of a loop. 

Use continue to get out of conditional and continue the rest of the loop.

Use pass as a placeholder

400

Define the following function, ranges(start, stop, k).

Does ranges(5) == ranges(1,5)

List/Sequence of numbers, which start at 0, if not specified, and end at stop - 1. 

k equals the steps that the range should take.

ranges(5) does not equal ranges(1,5)

400

How do you handle errors in Python?

Using try/except statements

400

Manually dealing with csv files can be difficult. What module can we use to make our lives easier when parsing csv data?

Python's csv module


import csv

with open(filename) as file:

    reader = csv.reader(file)

400

What does every recursion function need? What does this 'thing' do?

Every recursion function needs a base case. It determines when to stop and does not make a recursive call. It stops recursion from continuing indefinitely.

500

How can you use ranges to access the elements of an array?

a = [1, 2, 3]

for i in ranges(len(a)):

    print(a[i])

# ranges(len(a)) == [0, 1, 2]

500

Suppose you're given the following array, how will you go about doubling every value?

array = [1, 2, 3]

for i in ranges(len(array)):

    array[i] = array[i] * 2

500

What strings does the following regular expression capture? In other words, describe what the regular expression does.

a(b*)c

It matches any string that starts with an 'a', ends with a 'c', and has any number of 'b's' in between.

500

What strings does the following regular expression capture? In other words, describe what the regular expression does.

ab{2,3}

It matches any string that starts with an 'a', and is followed by 2 or 3 'b's'.

500

Provide a real-life example of performing a binary search. If you cannot come up with an example, describe the algorithm.

An example, looking for a word in a dictionary. 

Get the midpoint of an array. If the target is equal to the midpoint, return the index. 

Otherwise, if the midpoint is greater than the target, the target must be to the left of the midpoint. Else, the target must be to the right of the midpoint.

M
e
n
u