python

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

Left-sided binding determines that the result of the following expression: 1 // 2 * 3

0

What is the output of the following snippet if the user enters two lines containing 11 and 4 respectively? x = int(input()) y = int(input()) x = x % y x = x % y y = y % x print(y) 1 2 3 4

1

What is the output of the following snippet? z = y = x = 1 print(x, y, z, sep='*') 1 1 1 1*1*1 x*y*z x y z

1*1*1

What is the output of the following snippet? x = 1 / 2 + 3 // 3 + 4 ** 2 print(x) 8.5 17 17.5 8

17.5

What is the output of the following snippet? my_list = [3, 1, -2] print(my_list[my_list[-1]]) -2 3 1 -1

1?????

What is the output of the following code? tup = (1, 2, 4, 8) tup = tup[1:-1] tup = tup[0] print(tup) (2, ) the snippet is erroneous (2) 2

2

What is the output of the following snippet? a = 1 b = 0 c = a & b d = a | b e = a ^ b print(c + d + e) 3 2 1 0

2

What is the output of the following snippet? my_list = [1, 2, 3, 4] print(my_list[-3:-2]) [2, 3] [] [2] [2, 3, 4]

2

What is the output of the following snippet? x = 1 y = 2 z = x x = y y = z print(x, y) 2 2 2 1 1 2 1 1

2 1

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

21

What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively? x = input() y = input() print(x + y) 6 24 2 4

24

What is the output of the following snippet if the user enters two lines containing 3 and 6 respectively? x = input() y = int(input()) print(x * y) 18 333333 666 36

333333

After execution of the following snippet, the sum of all vals elements will be equal to: vals = [0, 1, 2] vals.insert(0, 1) del vals[1] 3 4 2 5

4

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

4

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

4

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

4

What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively? x = int(input()) y = int(input()) print(x + y) 24 6 2 4

6

What is the output of the following snippet? t = [[3-i for i in range (3)] for j in range (3)] s = 0 for i in range(3): s += t[i][i] print(s) 2 6 4 7

6

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

6

What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively? x = int(input()) y = int(input()) x = x / y y = y / x print(y) the code will cause a runtime error 8.0 4.0 2.0

8.0

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

9

An operator able to check whether two values are equal is coded as: == != === =

==

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

Error

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

The None value can be compared with variables The None value can be assigned to variables

Select the true statements about the try-except block in relation to the following example. (Select two answers.) try: # Some code is here... except: # Some code is here... 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. The code that follows the except statement will be executed if the code in the try clause runs into an error. If you suspect that a snippet may raise an exception, you should place it in the try block. The code that follows the try statement will be executed if the code in the except clause runs into an error.

The code that follows the except statement will be executed if the code in the try clause runs into an error. If you suspect that a snippet may raise an exception, you should place it in the try block.

Which of the following statements are true? (Select two answers) The ** operator uses right-sided binding. The right argument of the % operator cannot be zero. The result of the / operator is always an integer value. Addition precedes multiplication.

The right argument of the % operator cannot be zero. The ** operator uses right-sided binding.

The value eventually assigned to x is equal to: x = 1 x = x == x True 1 0 False

True

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

True

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

Very very bad input...

What is the output of the following snippet? my_list = [1, 2, 3] for v in range(len(my_list)): my_list.insert(1, my_list[v]) print(my_list) [1, 2, 3, 3, 2, 1] [1, 2, 3, 1, 2, 3] [1, 1, 1, 1, 2, 3] [3, 2, 1, 1, 2, 3]

[1, 1, 1, 1, 2, 3]

What is the output of the following snippet? my_list_1 = [1, 2, 3] my_list_2 = [] for v in my_list_1: my_list_2.insert(0, v) print(my_list_2) [3, 2, 1] [3, 3, 3] [1, 1, 1] [1, 2, 3]

[3, 2, 1]

Which of the following variable names are illegal? (Select two answers) True and true TRUE

and True

The print() function can output values of: any number of arguments (including zero) not more than five arguments just one argument any number of arguments (excluding zero)

any number of arguments (including zero)

Which one of the following lines properly starts a parameterless function definition? def fun: function fun(): def fun(): fun function():

def fun():

Which of the following lines properly starts a function using two parameters, both with zeroed default values? fun fun(a=0, b): fun fun(a, b=0): def fun(a=0, b=0): def fun(a=b=0):

def fun(a=0, b=0):

The following snippet: def func(a, b): return a ** a print(func(2)) will output 4 will return None will output 2 is erroneous

error?????

How many hashes (#) will the following snippet send to the console? var = 1 while var < 10: print("#") var = var << 1 eight four one two

four

The result of the following division: 1 / 1 cannot be evaluated is equal to 1 is equal to 1.0 cannot be predicted

is equal to 1.0

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] may be illegal if the tuple contains strings can be executed if and only if the tuple contains at least two elements is illegal is fully correct

is illegal

A function defined in the following way: (Select two answers) def function(x=0): return x must be invoked with exactly one argument may be invoked with exactly one argument may be invoked without any argument must be invoked without any argument

may be invoked with exactly one argument may be invoked without any argument

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)) no output, the snippet is erroneous ['Mary', 'had', 'a', 'little', 'lamb'] ['Mary', 'had', 'a', 'lamb'] ['Mary', 'had', 'a', 'ram']

no output, the snippet is erroneous

Take a look at the snippet, and choose the true statements: (Select two answers) nums = [1, 2, 3] vals = nums del vals[1:2] nums and vals refer to the same list nums is longer than vals nums and vals are of the same length nums is replicated and assigned to vals

nums and vals refer to the same list nums and vals are of the same length

Which of the following sentences are true? (Select two answers) nums = [1, 2, 3] vals = nums[-1:-2] nums is longer than vals nums and vals are two different lists nums and vals are of the same length vals is longer than nums

nums is longer than vals nums and vals are two different lists

The 0o prefix means that the number after it is denoted as:

octal

How many stars (*) will the following snippet send to the console? i = 0 while i <= 5 : i += 1 if i % 2 == 0: break print("*") two zero one three

one

Question 6: What is the output of the following snippet? x = 1 y = 1.0 z = "1" if x == y: print("one") if y == int(z): print("two") elif x == y: print("three") else: print("four")

one two

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.keys()): k = dictionary[i] # Insert your code here. print(k[0]) print(k) print(k["0"]) print(k['0'])

print(k[0])

The second assignment: vals = [0, 1, 2] vals[0], vals[2] = vals[2], vals[0] doesn't change the list reverses the list extends the list shortens the list

reverses the list

The meaning of the keyword parameter is determined by:

the argument's name specified along with its value

What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively? x = int(input()) y = int(input()) x = x // y y = y // x print(y) the code will cause a runtime error 2.0 8.0 4.0

the code will cause a runtime error

What is the output of the following snippet? my_list = [[0, 1, 2, 3] for i in range(2)] print(my_list[2][0]) 2 0 1 the snippet will cause a runtime error

the snippet will cause a runtime error

The fact that tuples belong to sequence types means that: they are actually lists 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 can be indexed and sliced like lists

How many elements does the my_list list contain? my_list = [i for i in range(-1, 2)] four one two three

three

How many hashes (#) will the following snippet send to the console? var = 0 while var < 6: var += 1 if var % 2 == 0: continue print("#") two three one zero

three

How many hashes (#) will the following snippet send to the console? for i in range(1): print("#") else: print("#") three one zero two

two

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

two??????

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)) is erroneous will output 4 will output 2 will output 16

will output 16


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

ATI Engage: Legal & Ethical Considerations

View Set

Chapter 1 The Science of Biology - Section 1-1 What Is Science? (pages 3-7)

View Set