Python II M4 test answers

¡Supera tus tareas y exámenes ahora con Quizwiz!

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

2

What is the output of the following snippet? def any(): print(var + 1,end="") var = 1 any() print(var)

21

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? def fun(x): global y y = x * x return y fun(2) print(y)

4

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

4

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

6

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

9

Which of the following statements is false?

The none value may not be used outside of functions

A built‑in function is a function which:

comes with Python, and is an integral part of python

Which of the following lines properly starts a parameterless function definition?

def fun():

Which of the following lines properly starts a function using two parameters, both with zeroed default values?

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

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

is erroneous

Assuming that tuple is a correctly created tuple, the fact that tuples are immutable means that the following instruction: tuple[1] = tuple[1] + tuple[0]

is illigal

A function defined in the following way: def function(x=0): return x

may be invoked without any argument, or with just one

What code would you insert into the commented line to obtain the output that reads: a b c Code: dict = { } list = ['a','b','c','d'] for i in range(len(list) - 1): dict[list[i]] = ( list[i], ) for i in sorted(dict.keys()): k = dict[i] # insert your code

print(k[0])

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

the code will cause a runtime error

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

the snippet is erroneous

The fact that tuples belong to sequence types means:

they can be indexed and sliced like lists

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

two

The following snippet: def func1(a): return a ** a def func2(a): return func1(a)*func1(a) print(func2(2))

will output 16


Conjuntos de estudio relacionados

Apparel 1: Industrial Revolution Notes

View Set

Chapter 16: Nursing Assessment Chapter 17: Nursing Diagnosis Chapter 18: Planning Nursing Care Chapter 19: Implementing Nursing Chapter 20: Evaluation

View Set

Public Speaking (Chpt 5) Study Guide

View Set

SFL 210 Human Development BYU Exam 3

View Set

LearningCurve 9a) Puberty Begins; Physical and Sexual Growth

View Set

Reading Comp. Final Review - Read & Use The Mystery of Coincidence

View Set

Environmental Science Cunningham, 7th ed Ch 9

View Set