CSC 1302 - Exam 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

41) Which correctly calls the add() function? def add(a, b, c): return a + b + c a. add(2 4 6) b. add(2 + 4 + 6) c. add(2; 4; 6) d. add(2, 4, 6)

d. add(2, 4, 6)

1) Which built-in object is mutable? a. bool b. int c. str d. list

d. list

10) Which of the following symbols can be used as part of an identifier? a. @ b. $ c. & d. _ (underscore)

d. underscore

20) Which statement removes the last element of my_list? a. my_list.pop(len(my_list) b. my_list.pop(len(my_list)-1) c. my_list.remove(len(my_list)) d. my_list.remove(len(my_list)-1)

my_list.pop(len(my_list)-1)

15 _____ 3 = 0 a. % b. / c. // d. *

a. %

28) Which expression is equivalent to: not x and y == a and b? a. (not (x and y)) == (a and b) b. ((not x) and y) and (a and b) c. not ((x and (y == a)) and b) d. ((not x) and (y == a)) and b

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

31) Which input value causes "Goodbye" to be output next? x = int(input()) while x >= 0: # Do something x = int(input()) print('Goodbye') a. -1 b. 0 c. 1 d. No such value

a. -1

29) What is the ending value of a when b is assigned with the value 5? a = 7 a = b + 5 if b > 5 else 0 a. 0 b. 5 c. 7 d. 10

a. 0

24) What is the value of x after the following code is executed? x = 17 if x * 2 <= 34: x = 0 else: x = x + 1 x = x + 1 a. 1 b. 18 c. 19 d. 35

a. 1

2) What is output? class Student: def __init__(self): self.age = 0 self.height = 0 self.weight = 0 student1 = Student() student1.age = 10 student2 = Student() student2.height = 155 print(student1.age, student1.weight, student1.height) print(student2.age, student2.weight, student2.height) a. 10 0 0 0 0 155 b. 155 0 0 0 0 10 c. 10 10 10 155 155 155 d. 10 0 155 10 0 155

a. 10 0 0 0 0 155

30) How many times will the body of the loop execute? my_list = [6, 2, 8, -1, 12, 15, -7] x = Get first my_list value While x is not negative: put "Positive number!" to output x = Get next my_list value Put "Done" to output a. 3 b. 4 c. 5 d. 7

a. 3

37) How many times will the print statement execute? for i in range(1, 3): for j in range(8, 12, 2): print(f'{i}. {j}') a. 4 b. 6 c. 9 d. 36

a. 4

17) Which of the following statements about my_list is false? my_list = ['JFK', 'LAX', 'MIA'] a. The element at index 1 is 'JFK' b. The list has a length of 3 c. The list elements are all strings d. The index of the last item in the list is 2

a. The element at index 1 is 'JFK'

32) Which is an essential feature of a while loop having the following form? while loop_expression: loop_body a. The loop_expression should be affected by the loop_body b. The loop_expression should not be affected by the loop_body c. The loop_body should get user input d. The loop_body should update at least two variables

a. The loop_expression should be affected by the loop_body

9) What happens when an object's reference count is zero? a. The object is no longer referenced. b. The object is ready for memory allocation. c. The object is being referenced. d. The object will be deallocated from memory immediately.

a. The object is no longer referenced.

46) What is output? my_string = 'What is your name?' print(my_string.split('?')) a. ['What is your name', ''] b. ['What is your name', '?'] c. ['What is your name?', ''] d. ['What', 'is', 'your', 'name', '?']

a. ['What is your name', '']

48) What is output? b1 = [7, 5, 9, 6] b1 = sorted(b1) b2 = b1 b2.append(2) print(b1, b2) a. [5, 6, 7, 9, 2] [5, 6, 7, 9, 2] b. [5, 6, 7, 9] [2, 5, 6, 7, 9] c. [2, 5, 6, 7, 9] [2, 5, 6, 7, 9] d. [5, 6, 7, 9] [5, 6, 7, 9, 2]

a. [5, 6, 7, 9, 2] [5, 6, 7, 9, 2]

12) A python code only runs the except block when _____. a. all the statements in the try block are executed. b. the programmer manually calls the except block. c. an error occurs anywhere in the code. d. an error occurs in the preceding try block.

a. all the statements in the try block are executed.

1) A sequence of instructions that solves a problem is called _____ a. an algorithm b. a process c. an allegory d. turtle graph

a. an algorithm

26) What conditions have to be true to make the following code display "B"? if color == 'red': if style < 3: print('A') elif style < 5: print('B') else: print('C') elif color == 'blue': print('D') a. color is 'red' and style is 4 b. color is 'red' and style is 5 c. color is 'red' and style is 6 d. color is 'blue' and style is 3

a. color is 'red' and style is 4

13) Which of the following is the correct syntax for a multiple exception handler? a. except (NameError, AttributeError): b. except [NameError, AttributeError]: c. except NameError AttributeError: d. except NameError, AttributeError:

a. except (NameError, AttributeError)

15) Which XXX generates the following output? Division by zero 100 50 33 25 my_list = [0, 1, 2, 3, 4] for i in my_list: try:if i == 0: raise ZeroDivisionError('Division by zero') else: num = 100 // i print(num) XXX a. except ZeroDivisionError as e: print(e) b. except e: print(e) c. except ZeroDivisionError: print(except) d. except ZeroDivisionError: print(ZeroDivisionError)

a. except ZeroDivisionError as e: print(e)

A key aspect of an abstract data type is to facilitate _________. a. information hiding b. interface hiding c. information manipulation d. attribute manipulation

a. information hiding (COME BACK)

5) A(n) _________ represents a single instance of a class. a. instance object b. instance attribute c. class object d. class attribute

a. instance object

19) Which method call returns the number of elements in my_list? a. len(my_list) b. size(my_list) c. my_list.count() d. my_list.size()

a. len(my_list)

6) Which type of error does not cause the program to crash? a. logic error b. value error c. indentation error d. assignment error

a. logic error

47) Select the code that gives ['cat in a hat', 'fluffy dogs', 1989, 1990] as the output. a. new_list = ['1000', '2000', '3000', 'cat in a hat', 'fluffydogs'] print(new_list[-2:] + [1989, 1990]) b. new_list = ['cat in a hat', 'fluffy dogs','1000', '2000','3000'] print(new_list[-2:] + [1989, 1990]) c. new_list = ['1000', '2000', '3000', 'cat in a hat', 'fluffydogs'] print(new_list[-1:] + [1989, 1990]) d. new_list = ['1000', '2000', '3000', 1989, 1990] print(new_list[-2:] + ['cat in a hat', 'fluffy dogs'])

a. new_list = ['1000', '2000', '3000', 'cat in a hat', 'fluffydogs'] print(new_list[-2:] + [1989, 1990])

40) 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}') a. parameter b. argument c. property d. value

a. parameter

2) Which symbol represents the multiplication operation in programming? a. . b. * c. x d. ( )

b. *

34) What sequence is generated by range(4)? a. 4 b. 0 1 2 3 c. 1 2 3 4 d. 0 1 2 3 4

b. 0 1 2 3

38) What is the output? id_list = [13, 984, 231, 140] for id in id_list: if id != 231: print(id, end=' ') else: print('Done') a. Done b. 13 984 Done c. 13 984 231 140 Done d. 13 984 140 Done

b. 13 , 984 Done

25) What is x's final value? x = 10 y = 20 if y <= 2 * x: x = x + 5 else: x = x * 2 a. 10 b. 15 c. 20 d. 25

b. 15

Consider the following program: t = 15 t = t * 2 t = t + 1 t = t - 4 put t What does the program produce as output? a. 11 b. 27 c. 12 d. 15

b. 27

50) What will be the date type for type(list_name.sort()) and type(sorted(list_name))? a. < class 'NoneType'>, < class 'NoneType'> b. < class 'list'>, < class 'NoneType'> c. < class 'list'>, < class 'list'> d. < class 'NoneType'>, < class 'list'>

b. <class 'list'>, <class 'NoneType'>

7) Which type of program converts a high-level language program into machine instructions? a. App b. Compiler c. Processor d. Assembler

b. Complier

35) Which of the following loops is best implemented with a for loop? a. Asking a user to enter names until the user enters 'Quit'. b. Counting the number of negative values in a list of integers. c. Starting from a user-entered integer, increment the value until the value is a prime number. d. Reading values from a temperature sensor until it gives a value greater than 100 degrees.

b. Counting the number of negative values in a list of integers.

43) How does the given function improve the code versus if no function was present? def fahrenheit_to_celsius(fahrenheit): return (fahrenheit - 32.0) * 5.0 / 9.0 fahrenheit = float(input()) c1 = fahrenheit_to_celsius(fahrenheit); c2 = fahrenheit_to_celsius(32.0); c3 = fahrenheit_to_celsius(72.0); a. The use of the function makes the program run faster b. The use of the function decreases redundant code c. The use of the function reduces the number of variables in the coded. d. The function does not improve the code

b. The use of the function decreases the redundant code

27) Which expressions for YYY and ZZZ will output "Young" when user_age is less than 20 and "Young but not too young" when user_age is between 10 and 20? age_type = ' ' if YYY: age_type = age_type + "Young" if ZZZ: age_type = age_type + " but not too young" print(age_type) a. YYY: user_age < 20 ZZZ: user_age < 10 b. YYY: user_age < 20 ZZZ: user_age > 10 c. YYY: user_age > 20 ZZZ: user_age < 10 d. YYY: user_age > 20 ZZZ: user_age > 10

b. YYY: user_age < 20 ZZZ: user_age > 10

Which of the following statements has a syntax error? Assume age and years are variables that have already been defined. a. age = years - 2 b. age + 2 = years c. age = 17 - 2 d. age = -15

b. age + 2 = years

11) The built-in Python function that gives an object's identity is: a. memory() b. id() c. type() d. identity()

b. id()

12) Assigning a value to a floating-point variable that is too large for the computer to represent is a condition called _____. a. bit error b. overflow c. overcapacity d. system error

b. overflow

15) Which print statement displays the value of a variable called argv in a module called sys? a. print(argv in sys) b. print(sys.argv) c. print(sys_argv) d. print(module sys var argv)

b. print(sys.argv)

14) Which of the following statements causes a ValueError to occur? a. try ValueError b. raise ValueError c. except ValueError d. except

b. raise ValueError

39) What is the output? for j in range(2): for k in range(4): if (k == 2): break print(f'{j}{k}', end=' ') a. 00 01 02 b. 00 01 02 03 c. 00 01 10 11 d. 00 01 02 10 11 12

c. 00 01 10 11

16) What is the ending value of z? x = 0.3 z = math.pow(math.ceil(x), 2) a. 0.0 b. 0.09 c. 1.0 d. 1.09

c. 1.0

18) What is the output? my_list = [2, 8, 3, 1, 18, 5] print(my_list[3] + my_list[1] * 2) a. 7 b. 10 c. 17 d. 18

c. 17

22) What is the value of x after the following code is executed? x = 7 If x < 7: x = x + 1 x = x + 2 a. 7 b. 8 c. 9 d. 10

c. 9

20) Which of the following statements is true for built-in exceptions? a. Even if the code can raise an exception, the code must always include an 'except' clause. b. A built-in exception cannot be explicitly called in a code. c. A built-in exception can be called in a code using a 'raise' statement. d. A built-in exception needs to be always caught in a try-except block.

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

23) For what values of x will "Medium" be output? If x > 40: Output "Large" Else If x > 20: Output "Medium" Else If x > 10: Output "Small" a. Any x larger than 20 b. Any x smaller than 40 c. Any x from 21 to 40 d. Any x from 10 to 40

c. Any x from 21 to 40

36) Which of the following loops is best implemented with a while loop? a. Checking to see if a list of integers contains the value 12. b. Counting how many keys in a dictionary start with the letter 'A'. c. Asking the user to enter positive integers, exiting by entering -1. d. Looping through the characters in a string, and displaying 'yes' if it contains a vowel.

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

3) A function defined within a class is known as a(n) _________. a. class attribute b. method object c. instance method d. class object

c. Instance method

44) What is the output? def print_water_temp_for_coffee(temp): if temp < 195: print('Too cold.') elif (temp >= 195) and (temp <= 205): print('Perfect temperature.') elif (temp > 205): print('Too hot.') print_water_temp_for_coffee(205) print_water_temp_for_coffee(190) a. Too cold. b. Perfect temperature. c. Perfect temperature. Too cold. d. Perfect temperature. Too cold.

c. Perfect temperature. Too cold.

8) RAM is an abbreviation that stands for: a. Real Analog Memory b. Ranged Access Memory c. Random Access Memory d. Random Abbreviated Memory

c. Random Access Memory

19) What happens when an unhandled exception occurs? a. The finally clause executes, and then the exception is re-raised. b. The finally clause executes, and then runs the try block again. c. The finally clause executes, and the code finishes. d. The finally clause executes, and the code returns -1.

c. The finally clause executes, and the code finishes.

42) Which of the following is not a reason to use functions? a. To avoid writing redundant code b. To improve code readability c. To support modular development d. To make the code run faster

c. To support modular development

16) The _____ keyword binds a name to the exception being handled a. raise b. try c. as d. except

c. as

6) A ________ consists of methods to interact with an instance. a. class object b. class attribute c. class instantiation d. class interface

c. class instantiation

4) A(n) _________ acts as a factory that creates instance objects. a. instance object b. instance attribute c. class object d. class attribute

c. class object

11) Python uses _________ constructs to handle errors during execution. a. control b. class method c. exception-handling d. conditional

c. exception-handling

49) 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) a. i, ii, iv b. i, ii, iii c. i, ii d. i, ii, iii, iv

c. i, ii (COME BACK)

14) Which statement makes the code in the math module available? a. use math b. allow math c. import math d. include math

c. import math

8) Which of the following functions returns a Boolean value depending on whether a given variable matches a given type? a. isvalue() b. isnan() c. isinstance() d. isdtype()

c. isinstance()

Dividing by zero is an example of which type of error? a. runtime b. syntax c. logic d. infinity

c. logic

45) Which of the following methods will change the string 'Python Programming' into' PYTHON PROGRAMMING'? a. title() b. isupper() c. upper() d. capitalize()

c. upper()

21) Which statement correctly creates a new tuple west_cities with elements 'Vancouver', 'Portland', 'Eugene' in that order? a. west_cities = ['Vancouver', 'Portland', 'Eugene'] b. west_cities = ('Portland', 'Vancouver', 'Eugene') c. west_cities = ('Vancouver', 'Portland', 'Eugene') d. west_cities = ['Portland', 'Vancouver', 'Eugene']

c. west_cities = ('Vancouver', 'Portland', 'Eugene')

Which symbol is used in Python to create a comment? a. * b. C c. // d. #

d. #

18) What is output? def get_name(name): if len(name) <= 2: raise ValueError('You need to enter your complete name.') return name def get_age(age): if age > 100: raise ValueError('Please enter some value') return age try: name = get_name('Mike') school_name = get_age('3') print(f'{name} is {school_name} years old.') except ValueError as excpt: print(excpt) except: print('Error!') a. You need to enter your complete name. b. Please enter some value c. Mike is 3 years old. d. Error!

d. Error

10) Which of the following requests memory from the operating system? a. Reference counter b. Python runtime c. Python compiler d. Memory allocation device

d. Memory allocation device

33) What is the output? count = 0 while count < 3: print('loop') count = count + 1 print(f'Final value of count: {count}') a. Prints 'loop' once, then 'final value of count: 1' b. Prints 'loop' three times, then 'final value of count: 3' c. Prints 'loop' three times, then 'final value of count: 4' d. Prints 'loop' forever (infinite loop)

d. Prints 'loop' forever (infinite loop)

17) What happens when a raise statement is encountered in a function? a. The code executes the next line in the function. b. The raise exception is printed immediately. c. An exception is immediately executed by the function returning -1. d. The function is exited with no return.

d. The function is exited with no return


संबंधित स्टडी सेट्स

MD33000 필수어휘 3/6 (DE~EX) 예문, 파생어

View Set

Chapter 5: Cells-The Working Units of Life

View Set

Acctg 201: Chapter 5 Learnsmart questions

View Set

Data Science Interview Questions

View Set