IST 290 final test

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

What is the output of the following snippet? def fun(inp=2, out=3): return inp * out print(fun(out=2)) A. the snippet is erroneous and will cause SyntaxError B. 4 C. 6 D. 2

B. 4

What is the output of the following snippet? my_list = [x * x for x in range(5)] def fun(lst): del lst[lst[2]] return lst print(fun(my_list)) A. [0, 1, 9, 16] B. [1, 4, 9, 16] C. [0, 1, 4, 16] D. [0, 1, 4, 9]

D. [0, 1, 4, 9]

What is the output of the following snippet? tup = (1, 2, 4, 8) tup = tup[-2:-1] tup = tup[-1] print(tup) A. 4 B. (4) C. (4,) D. 44

A. 4

What is the expected behavior of the following program? try: print(5/0) break except: print("Sorry, something went wrong...") except (ValueError, ZeroDivisionError): print("Too bad...") A. The program will cause a SyntaxError exception. B. The program will cause a ZeroDivisionError exception and output the following message: Too bad... C. The program will cause a ZeroDivisionError exception and output a default error message. D. The program will cause a ValueError exception and output a default error message. E. The program will cause a ValueError exception and output the following message: Too bad... F. The program will raise an exception handled by the first except block.

A. The program will cause a SyntaxError exception.

Which of the following variable names are illegal and will cause the SyntaxError exception? (Select two answers) A. for B. in C. In D. print

A. for B. in

Assuming that my_tuple is a correctly created tuple, the fact that tuples are immutable means that the following instruction: my_tuple[1] = my_tuple[1] + my_tuple[0] A. is illegal B. can be executed if and only if the tuple contains at least two elements C. may be illegal if the tuple contains strings D. is fully correct

A. is illegal

The meaning of a positional argument is determined by: A. its position within the argument list B. its value C. its connection with existing variables D. the argument's name specified along with its value

A. its position within the argument list

Which of the following sentences are true about the code? (Select two answers) nums = [1, 2, 3] vals = nums A. nums has the same length as vals B. vals is longer than nums C. nums and vals are different lists D. nums and vals are different names of the same list

A. nums has the same length as vals D. nums and vals are different names of the same list

An operator able to check whether two values are not equal is coded as: A. <> B. != C. =/= D. not ==

B. !=

What is the output of the following piece of code? x = 1 y = 2 x, y, z = x, x, y z, y, z = x, y, z print(x, y, z) A. 1 2 1 B. 1 1 2 C. 2 1 2 D. 1 2 2

B. 1 1 2

What is the output of the following snippet? dct = {} dct['1'] = (1, 2) dct['2'] = (2, 1) for x in dct.keys(): print(dct[x][1], end="") A. (1,2) B. 21 C. 12 D. (2,1)

B. 21

Which of the following snippets shows the correct way of handling multiple exceptions in a single except clause? # A: except (TypeError, ValueError, ZeroDivisionError): # Some code. # B: except TypeError, ValueError, ZeroDivisionError: # Some code. # C: except: (TypeError, ValueError, ZeroDivisionError) # Some code. # D: except: TypeError, ValueError, ZeroDivisionError # Some code. # E: except (TypeError, ValueError, ZeroDivisionError) # Some code. # F: except TypeError, ValueError, ZeroDivisionError # Some code. A. A, C, and D B. A only C. F only D. A and B E. D and E F. B and C G. A and F

B. A only

my_list = [1, 2] for v in range(2): my_list.insert(-1, my_list[v]) print(my_list) A. [1, 2, 2, 2] B. [1, 1, 1, 2] C. [1, 2, 1, 2] D. [2, 1, 1, 2]

B. [1, 1, 1, 2]

Which of the following lines correctly invoke the function defined below? (Select two answers) def fun(a, b, c=0): # Body of the function. A. fun() B. fun(0, 1, 2) C. fun(b=0, a=0) D. fun(b=1)

B. fun(0, 1, 2) C. fun(b=0, a=0)

The result of the following division: 1 // 2 A. cannot be predicted B. is equal to 0 C. is equal to 0.0 D. is equal to 0.5

B. is equal to 0

The following snippet: def func(a, b): return b ** a print(func(b=2, 2)) A. will output None B. is erroneous C. will output 2 D. will output 4

B. is erroneous

How many hashes (#) will the following snippet send to the console? lst = [[x for x in range(3)] for y in range(3)] for r in range(3): for c in range(3): if lst[r][c] % 2 != 0: print("#") A. six B. three C. nine D. zero

B. three

The following snippet: def function_1(a): return None def function_2(a): return function_1(a) * function_1(a) print(function_2(2)) A. will output 16 B. will cause a runtime error C. will output 2 D. will output 4

B. will cause a runtime error

What will be the output of the following snippet? a = 1 b = 0 a = a ^ b b = a ^ b a = a ^ b print(a, b) A. 1 1 B. 0 0 C. 0 1 D. 1 0

C. 0 1

What is the output of the following piece of code? x = 1 // 5 + 1 / 5 print(x) A. 0.5 B. 0.4 C. 0.2 D. 0

C. 0.2

What is the output of the following snippet? def fun(x): if x % 2 == 0: return 1 else: return 2 print(fun(fun(2))) A. 2None B. the code will cause a runtime error C. 2 D. 1

C. 2

What is the output of the following piece of code if the user enters two lines containing 3 and 6 respectively? 1 2 3 4 y = input() x = input() print(x + y) A. 3 B. 6 C. 63 D. 36

C. 63

What value will be assigned to the x variable? z = 0 y = 10 x = y < z and z > y or y < z and z < y A. 1 B. 0 C. False D. True

C. False

What is the output of the following snippet? dct = {'one': 'two', 'three': 'one', 'two': 'three'} v = dct['three'] for k in range(len(dct)): v = dct[v] print(v) A. two B. ('one', 'two', 'three') C. one D. three

C. one

How many stars (*) will the following snippet send to the console? i = 0 while i < i + 2 : i += 1 print("*") else: print("*") A. zero B. one C. the snippet will enter an infinite loop, printing one star per line D. two

C. the snippet will enter an infinite loop, printing one star per line

How many elements does the lst list contain? lst = [i for i in range(-1, -2)] A. three B. one C. zero D. two

C. zero

What is the output of the following piece of code if the user enters two lines containing 3 and 2 respectively? x = int(input()) y = int(input()) x = x % y x = x % y y = y % x print(y) A. 2 B. 1 C. 3 D. 0

D. 0

What is the output of the following piece of code if the user enters two lines containing 2 and 4 respectively? x = float(input()) y = float(input()) print(y ** (1 / x)) A. 0.0 B. 1.0 C. 4.2 D. 2.0

D. 2.0

What will happen when you attempt to run the following code? print(Hello, World!) A. The code will raise the TypeError exception. B. The code will print Hello, World! to the console. C. The code will raise the ValueError exception. D. The code will raise the SyntaxError exception. E. The code will raise the AttributeError exception.

D. The code will raise the SyntaxError exception.

What is the output of the following piece of code? print("a", "b", "c", sep="sep") A. abc B. a b c C. asepbsepcsep D. asepbsepc

D. asepbsepc

Take a look at the snippet and choose the true statement: nums = [1, 2, 3] vals = nums del vals[:] A. the snippet will cause a runtime error B. vals is longer than nums C. nums is longer than vals D. nums and vals have the same length

D. nums and vals have the same length

What is the output of the following snippet? dd = {"1": "0", "0": "1"} for x in dd.vals(): print(x, end="") A. 1 0 B. 0 0 C. 0 1 D. the code is erroneous (the dict object has no vals() method)

D. the code is erroneous (the dict object has no vals() method)

What is the expected behavior of the following program? foo = (1, 2, 3) foo.index(0) A. The program will output 1 to the screen. B. The program will cause a SyntaxError exception. C. The program will cause an AttributeError exception. D. The program will cause a TypeError exception. E. The program will cause a ValueError exception.

E. The program will cause a ValueError exception.

What is the output of the following code if the user enters a 0? try: value = input("Enter a value: ") print(int(value)/len(value)) except ValueError: print("Bad input...") except ZeroDivisionError: print("Very bad input...") except TypeError: print("Very very bad input...") except: print("Booo!") A. Very bad input... B. Booo! C. Very very bad input... D. Bad input... E. 1.0 F. 0.0

F. 0.0

What is the output of the following snippet? def fun(x, y): if x == y: return x else: return fun(x, y-1) print(fun(0, 3)) A. 0 B. 2 C. the snippet will cause a runtime error D. 1

A. 0


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

business ethics and social responsibility

View Set

Chapter 5 Introduction to the Nursing Process

View Set

Periodic Table - Elements that begin with letter "u"

View Set

800-171 CUI Controls (124 Controls)

View Set

Technology&Trade - The Ricardian Model

View Set

Chapter 15 Questions - Anxiety and Obsessive-Compulsive Disorders

View Set

Chapter 14: Telephone Techniques

View Set

Chapter 2: The Constitution and the Founding (Inquizitive)

View Set

Plate Boundaries, Bathymetry, Ocean Basins

View Set