PE1 Summary Test

Ace your homework & exams now with Quizwiz!

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))

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))

2.0

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

True

What is the output of the following piece of code? print("a", "b", "c", sep="sep")

asepbsepc

What is the output of the following piece of code if the user enters two lines containing 3 and 6 respectively? y = input() x = input() print(x + y)

63

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

1, 1, 1, 2

Which of the following variable names are illegal and will cause the SyntaxError exception? (select two answers)

in for

The meaning of a positional argument is determined by:

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

nums and vals are different names on the same list nums has the same length as vals

The following snippet: def function_1(a): return None def function_2(a): return function_1(a) * function_1(a) print(function_2(a))

will cause a runtime error

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

4

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

4

What is the output for 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)

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="")

21

How many hashes(#) will the following snippet send to the console? lst = [[x for x in range (3)] for y range in (3)] for r in range (3): for c in range (3): if lst [r][c] % 2 != 0: print("#")

three

How many elements does the lst contain? lst = [i for i in range (-1, -2) ]

zero

What is the output of the following snippet? def fun( x ): if x % 2 == 0: return 1 else: return 2 print(fun(fun(2)))

2

Which of the following lines correctly invoke the function below? (select two answers) def fun(a, b, c=0): # Body of the function.

fun (0, 1, 2) fun (b=0, a=0)

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

!=

What is the following snippet? dd = {"1": "0", "0": "1"} for x in dd.vals(): print (x, ends"")

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

How many stars(*) will the following snippet send to the console? i = 0 while i < i+2 : i += 1 print("*") else: print("*")

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

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)

0

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)

0 1

What is the output of the following snippet? def fun(lst): del lst[ lst[ 2 ] ] return lst print(fun(my_list))

0, 1, 4, 9

What is the output of the following piece of code? x = 1 // 5 + 1 / 5 print(x)

0.2

The result of the following division: 1 // 2

is equal to 0

The following snippet: def func(a, b): return b ** a print(func(b=2, 2))

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 ]

is illegal

Take a look at the snippet, and choose the true statement: nums = [1, 2, 3] vals = nums del vals[ : ]

nums and vals have the same length

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)

one


Related study sets

US History - The Great Depression and The New Deal

View Set

Digestive System and Metabolism 3.2.2 & 3.2.5

View Set

Spirituality Custom Adaptive Quizzes

View Set

Module 2: Homeostasis and Regulation

View Set

Week 2: HIV/AIDS Animation Exercise (pathology B)

View Set

ANESTESIA TEMA 3 TRANQUILLANTI E SEDATIVI

View Set

Quiz 1, Unit 1 study guide, Quiz 3, Quiz 2, STUDY NOTES SOCIAL PSYCH FINAL

View Set

PSYC 309 - Final Exam (Cumulative)

View Set