Study Guide 1 CS

Ace your homework & exams now with Quizwiz!

36) If the base condition is not defined in the recursive function, _____.

d. the program gets into an infinite loop

13) Which of the following is the correct syntax for a multiple exception handler?

except (NameError, AttributeError):

11) Python uses _________ constructs to handle errors during execution.

exception handling

Which statement opens a file for appending?

file = open('ABC.txt', 'a')

Identify the code that generates 'The value of pi is: 3.14'

from math import pi print('The value of pi is: {0:.2f}'.format(pi))

Which of the following options can sort the list in descending order? i. list_name.sort(reverse=True) ii. sorted(list_name, reverse=True) iii. sorted(list_name)[::-1] iv. sorted(list_name)

i, ii, iii

The built-in Python function that gives an object's identity is

id()

Which statement makes the code in the math module available?

import math

Linear search is a search algorithm that searches the list _____

in ascending order and then searches the list until the search key is found

7) A key aspect of an abstract data type is to facilitate _________.

information hiding

Which of the following functions returns a Boolean value depending on whether a given variable matches a given type?

isinstance()

While adding output statements to debug recursive functions, _____ the print statements to show the current depth of recursion.

left allign

19) Which method call returns the number of elements in my_list?

len(my_list)

1) Which built-in object is mutable?

list

A function defined within a class is known as a(n) _________.

method object

20) Which statement removes the last element of my_list?

my_list.pop(len(my_list)-1)

A(n) _________ represents a single instance of a class

object

Which is the correct syntax for opening a file in Python?

open()

12) Assigning a value to a floating point variable that is too large for the computer to represent is a condition called

overflow

A(n) _____ is a directory that gives access to all of the modules stored in a directorywhen imported.

package

24) The reload() function returns the _____.

pre-existing namespace

Which print statement displays the value of a variable called argv in a module called sys?

print(sys.argv)

10) Which of the following requests memory from the operating system?

python runtime

14) Which of the following statements causes a ValueError to occur?

raise valueError

Dividing by zero is an example of which type of error?

run-time

Which of the following symbols can be used as part of an identifier?

underscore

Which of the following methods will change the string 'Python Programming' into'PYTHON PROGRAMMING'?

upper()

31) Which code opens a csv file with semicolon as a delimiter?

with open("my_file.csv", "r") as file: csv_data = csv.reader("my_file.csv","delimiter;").

45) What is the worst-case runtime for a merge sort?

𝑂(𝑁log𝑁)

Which symbol is used in Python to create a comment?

#

15__3 = 0

%

Which expression is equivalent to: not x and y == a and b?

((not x) and (y == a)) and b

What symbol represents multiplication

*

34) What sequence is generated by range(4)?

0 1 2 3

Iist has 20 elements, how many outer loop iterations are executed for selection sort?

20

Consider the following program: t = 15 t = t * 2 t = t + 1 t = t - 4 put t What does the program produce as output?

27

44) In [2, 3, 6, 10, 20, 25, 100], how many elements will be checked to find the element20 using binary search?

3

20) Which of the following statements is true for built-in exceptions?

A built-in exception can be called in a code using a 'raise' statement

append

Adds input to the end of a list

Which of the following loops is best implemented with a while loop?

Asking the user to enter positive integers, exiting by entering -1

Which type of program converts a high-level language program into machineinstructions?

Complier

35) Which of the following loops is best implemented with a for loop?

Counting the number of negative values

32) _____ is a concept where the derived class acquires the attributes of its base class.

Inheritance

Which type of error does not cause the program to crash?

Logical Error

_____ is a sorting algorithm that divides a list into two halves, recursively sorts eachhalf, and then merges the sorted halves to produce a sorted list

Merge sort

_____ can be set to specify optional directories where modules are located.

PYTHONPATH

RAM is an abbreviation that stands for

Random Access Memory

17) What happens when a raise statement is encountered in a function?

The code executes the next line in the function

Which of the following statements about my_list is false?my_list = ['JFK', 'LAX', 'MIA']

The element at index 1 is JFK

32) Which is an essential feature of a while loop having the following form?

The loop_expression should be affected by the loop_body

What happens when an object's reference count is zero?

The object is no longer referenced

42) Which of the following is not a reason to use functions?

To make the code run faster

50) Which of the following is a good candidate for using recursive functions?

To solve the greatest common divisor (GCD) problem

Which statement is not true?

When adding a new derived class, a programmer has to change the base class as well.

What is output? my_string = 'What is your name?' print(my_string.split('?'))

['What is your name', '']

Given [0, 2, 4, 7, 92], i = 0, k = 4, what are the contents of the right partition?

[7, 92]

19) What happens when an unhandled exception occurs?

a. The finally clause executes, and then the exception is re-raised.

41) A base case is a _____.

a. case that returns a value without performing a recursive call

28) Identify the correct syntax used to write to a text file.

a. file = open('My_data.txt', 'w') file.write('This file contains data')

41) Which correctly calls the add() function?

add(2,4,6)

40) An indent variable _____ number of spaces on each iteration.

adds equal

1) A sequence of instructions that solves a problem is called _____

an algorithm

12) A python code only runs the except block when _____.

an error occurs in the preceding try block

In the following code, the variable val is the function call's _____. def calc_square_area(size): area = size * size return area val = float(input('Enter size of square: ')) square_area = calc_square_area(val) print(f'A square of size {val} has area {square_area}')

argument

16) The _____ keyword binds a name to the exception being handled.

as

33) Which statement is true about inheritance?

b. A class can serve as a base class for multiple derived classes.

22) Which of the following is true for an environment variable?

b. It is stored in the root folder of Python

During the merge sort operation for the list [89, 6, 8, 42, 60, 9, 20, 34], at what left and right partition position is 20 added to the temporary list?

b. Left position is 1 and right position is 7

43) How does the given function improve the code versus if no function was present?

b. The use of the function decreases redundant code

A derived class may define a method having the same name as the base classmeans that:

b. a base class method overrides the method of the derived class.

What is theending value of z? x = 0.3 z = math.pow(math.ceil(x), 2) a. 0.0 b. 0.09 c. 1.0

c. 1.0

38) Which is the best way to debug recursive functions?

c. Adding output statements with an indent to print statements at every iteration.

30) It is recommended to use a 'with' statement when opening files so that ____.

c. the file is closed when no longer needed

A(n) _________ acts as afactorythat creates instance objects.

class

6) A ________ consists of methods to interact with an instance.

class interface

What is the output? count = 0 while count < 3: print('loop') count = count + 1 print(f'Final value of count: {count}')

d. Prints 'loop' forever (infinite loop)


Related study sets

Ultimate! AP Psych Study Questions

View Set

License Suspension, Revocation, and Reinstatement

View Set

Factors that shift the demand curve

View Set

Psychology - Chapter 15: Psychological Disorders

View Set

BIO 3100 - CH 7 Pre Class Assignment

View Set

Development of the Fetal Heart & Circulation

View Set

Psych Methods 2314 B Sessions 5.1, 5.2, 5.3

View Set