wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CS 1400 Final Review

Total questions: 31

Worksheet time: 47mins

Name
Class
Date
1.

What is executed first in this code?

[Lecture 19]

a)

The return statement

b)

sum(vals)

c)

The multiply

2.

Which operation is performed first?

[Lecture 19]

a)

add

b)

divide

c)

subtract

d)

print

3.

Which of the following are true of recursion or recursive functions?

[Lecture 19]

a)

Recursion involves a base case and a recursive step.

b)

The base case of a recursive function is the first iteration of the recursion.

c)

Recursive functions invoke themselves to solve a smaller part of the same problem.

d)

Recursive solutions involve iterating by adding one to a counting variable.

4.

Write two functions:

1) iter_factorial takes an integer as the parameter, returns the factorial of that parameter. The factorial must be solved iteratively (e.g. without recursion).

2) recurs_factorial takes an integer as the parameter, returns the factorial of that parameter. The factorial must be solved recursively.

[Lecture 19/Lab 12]

4 lines
5.

What is the base case in this code?

[Lecture 20]

a)

number // 2

b)

1 + mystery

c)

return 1

d)

number <= 1

6.

What causes recursion to progress towards the base case?

[Lecture 20]

a)

number // 2

b)

1 + mystery

c)

return 1

d)

number <= 1

7.

What is the value of mystery(1)?

[Lecture 20]

a)

0.5

b)

0

c)

1

d)

Infinite recursion (Stack Overflow)

8.

What is the value of mystery(40)?

[Lecture 20]

a)

1

b)

5

c)

6

d)

7

9.

What does the function os.path.isfile(file_name) do?

[Lecture 20]

a)

Returns the full absolute path of file_name

b)

Returns true if file_name is a directory/folder

c)

Returns true if file_name is a file

d)

Returns the relative path of file_name

10.

Which of the following are examples of input for interactive programs?

[Lecture 21]

a)

Pressing a key

b)

Moving the mouse

c)

Clicking the mouse

d)

Touching the screen

11.

Which of the following are examples of output for interactive programs?

[Lecture 21]

a)

Images and graphics

b)

Text and messages

c)

Movement and updates

d)

Sounds

12.

Which of the following pseudocode implementations follow the basic structure of a video game that you have learned?

[Lecture 21]

a)
b)
c)
d)
13.

Why shouldn't we remove from a list while we are looping over it?

What should we do instead?

[Lecture 21]

a)

Modifying a list while we are looping over it could result in some elements being skipped.

We should use the built-in remove method for lists in Python as it is safe to use.

b)

Modifying a list while we are looping over it could result in some elements being skipped.

We should have a temporary list of things to keep, and then set that new list as the real list.

c)

Modifying a list while we are looping over it does not actually change the list, just creates a temporary instance of the changed list, so we will be changing the wrong list.

We should have a temporary list of things to keep, and then set that new list as the real list.

d)

Modifying a list while we are looping over it is not allowed in Python - it will throw an InvalidOperationException.

We should have a temporary list of things to keep, and then set that new list as the real list.

14.

What happens in this code?

[Lecture 25]

a)

5 is printed

b)

10 is printed

c)

An error occurs

15.

What happens in this code?

[Lecture 25]

a)

[5, 6] is printed

b)

[7, 8] is printed

c)

An error occurs

16.

What happens in this code?

[Lecture 25]

a)

[5, 6] is printed

b)

[7, 8] is printed

c)

An error occurs

17.

Which of the following are true of reassigning and modifying object variables in Python?

a)

Reassigning a variable will make the variable point somewhere else in memory

b)

Reassigning a variable will replace the value stored in memory at the same place

c)

Modifying the object referenced by a variable will throw an error as Python doesn't allow modification.

d)

Modifying the object referenced by a variable will go to the location in memory for that object and change it.

18.

What is the outcome of this code?

a)

Only the r2 rectangle has moved

b)

Only the r1 rectangle has moved

c)

Both rectangles have moved

d)

Neither rectangles have moved

19.

In the following code, which are the operators?

a)

-

b)

-

>

c)

-

>

and

d)

-

>

and

is_complete()

20.

In the following code, which are expressions?

a)

If a > b:

b)

a > b

c)

a - b

d)

x(a - b)

21.

What is the outcome if 5 is entered?

a)

5

b)

10

c)

55

d)

Type error

22.

What does this code print?

a)

1

b)

2

c)

3

d)

4

23.

Which expression matches this description:

True if x is between 5 and 10 (including 5 and 10)

a)

x > 5 or x < 10

b)

x >= 5 or x <= 10

c)

x >= 5 and x <= 10

d)

5 >= x and 10 <= x

24.

What is printed?

a)

-100

b)

-20

c)

-30

d)

-1

25.

What is printed?

a)

Nothing - an error is thrown because of stack overflow

b)

1

2

3

4

c)

4

d)

4

3

2

1

26.

Write a function called less_squares that will take an integer n as the parameter. This function should then print the square of each non-negative integer less than n on a new line. You should do this on paper by hand to practice writing code that way for the final.

Here is an example where n = 4:

0

1

4

9

This is because the numbers less than 4 are [0, 1, 2, 3], each of which match to one of the above squares.

4 lines
27.

Come up with an example problem where you would use each of the following loops:

Accumulation Loop

Optimization Loop

Searching Loop (over index values)

Searching Loop (over elements)

4 lines
28.

Consider this list of numbers: [-3, 0, 4, 5, 7, 8, 12, 14, 23]. If we use binary search as discussed in class to search for a target of 6 in this list, which indexes will be examined? Write them in the order that they are examined, and add a comma and a space in between indexes.

[Midterm 2]

(a)  

29.

Select the differences between sequential/linear search and binary search below.

[Midterm 2]

a)

Linear search examines every element sequentially until it finds the key, or reaches the end of the list.

b)

Binary search requires that the list be sorted, while linear search does not.

c)

Binary search works by repeatedly halving the search area.

d)

Linear search will examine only the first and last elements to decide if the key is in the list.

e)

Linear search examines every element (N elements), while binary search examines log(N)\log\left(N\right)  elements.

30.

Write a function called count_values that takes in a list parameter and returns a dictionary representing the number of times each value occurs in the list.

For example, count_values(["a", "b", "a", "c"]) should return {"a": 2, "b": 1, "c": 1}

[Midterm 2]

4 lines
31.

Rewrite the function below so that it only uses a single return statement that returns a logical expression and does not use any if statements.

4 lines