Python Essentials 1_Module 4

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is the output of the following snippet? def ant(): print(var + 1, end ='') var = 1 any() print(var) -12 -22 -11 -21

21

What is the output of the following snippet? def func_1(a): return a ** a def func_2(a): return func_1(a) * func_1(a) print(func_2(2)) A. will output 2 B. will output 16 C. will output 4 D. is erroneous

Answer: B

Which one if the following lines properly starts a parameterless function definition? A. def fun: B. def fun(): C. function fun(): D. fun function():

Answer: B

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

Answer: C. 4

What is the output of the following snippet? def fun(x): x += 1 return x x = 2 x = fun(x + 1) print(x) A. 3 B. 5 C. the code is erroneous D. 4

Answer: D

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

Answer: D

What is the output of the following snippet? my_list = ['Mary', 'had', 'a', 'little', 'lamb'] def my_list(my_list): del my_list[3] my_list[3] = 'ram' print(my_list(my_list)) A. ['Mary', 'had', 'a' ,'lamb'] B. ['Mary', 'had', 'a' ,'ram'] C. ['Mary', 'had', 'a' ,'little', 'lamb'] D. no output, the snippet is erroneous

Answer: D

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

Answer: D

What is the output of the following code? try: value = input("Enter a value: ") print(value/value) except: print("Bad input...") except ZeroDivisionError: print("Very bad input...") except TypeError: print("Very very bad input...") except: print("Booo!") -Booo! -Bad input... -Very very bad input... -Very bad input...

Answer: Very very bad input...

A built-in function is a function which: is hidden from programmers has been placed within your code by another programmer has to be imported before use comes with Python, ans is an integer part of Python

Answer: comes with Python, ans is an integer part of Python

The fact that tuples belong to sequence types means that: they can be indexed and sliced like lists they can be extended using the .append() method they can be modified using the del instruction they are actually lists

Answer: they can be indexed and sliced like lists

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

C. the code will cause a runtime error

What code would you insert instead of the comment to obtain the expected output? Expected output: a b c Code: dictionary = {} my_list = ['a', 'b', 'c', 'd'] for i in range(len(my_list) - 1): dictionary[my_list[i]] = (my_list[i], ) for i in sorted(dictionary.key()): k = dictionary[i] Insert your code here. print(k["0"]) print(k['0']) print(k) print(k[0]) A. print(k["0"]) B. print(k['0']) C. print(k) D. print(k[0])

D. print(k[0])

What is the output of the following snippet? def fun(x): global y y = x * x return y fun(2) print(y) A. the code will cause a runtime error B. 4 C. None D. 2

Answer: B

What is the output of the following snippet? def f(x): if x == 0: return 0 return x + f(x - 1) print(f(3)) A. 6 B. the code is erroneous C. 1 D. 3

Answer: A

What is the output of the following snippet? def fun(x, y, x): return x + 2 * y + 3 * z print(fun(0, z=1, y=3)) A. 9 B. 0 C. 3 D. the snippet is erroneous

Answer: A

Select the true statements about the try-exception block in relation to the following example. (Select two answers.) try: # Some code is here... except: # some code is here... A. if you suspect that a snippet may raise an exception, you should place it in the try block B. The code that follows the try statement will be executed if the code in the except clause runs into an error. C. The code that follows the except statement will be executed if the code in the try clause runs into an error. D. If there is a syntax error in code located in the try block, the except branch will not handle it, and a SyntaxError exception will be raised instead.

Answer: A and C

Which of the following statement are true? (Select two answers) A. The None value can be assigned to variables B. The None value cannot be used outside functions C. The None value can be used as an argument of arithmetic operators D. The None value can be compared with variables

Answer: A and D

Which of the following statements are true about a function defined in the following way? def function(x=0): return x A. The function may be invoked with exactly one argument B. The function may be invoked without any argument C. The function must be invoked with exactly one argument D. The function must be invoked without any argument

Answer: A and D

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

Answer: A. is erroneous

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. can be executed if and only if the tuple contains at least two elements B. is illegal C. may be illegal if the tuple contains string D. is fully correct

Answer: B


Kaugnay na mga set ng pag-aaral

Quiz 5 Review: Part 1 Momentum and Collision

View Set

Tradeoffs Associated with digital data 1-10

View Set

CS 332/ 532 Systems Programming Lecture Two Introduction

View Set