Quiz 1-5

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

In Python the syntax for iterations over list, string, and set is the same.

True

What is the output of the following?

True

What is the output after the following? x = [3,2,1] id_1 = id(x) x.sort() id_2 = id(x) y = [3,2,1] id_3 = id(y) y = sorted(y) id_4 = id(y) print(id_1==id_2, id_3==id_4

True, False

why do computers use zeros and ones

because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.

What collection would you use to store values in terms of key and values?

dictionary

Consider a Python function f(x, y). For which data types of parameters x and y is it possible to get the same result as passing by reference?

dictionary and set

x = 'abcdefgh' print(x[::-1][2:5])

fed

is the physical aspect of the computer that can be seen

hardware

A python line comment begins with

#

what is the output after the following statement? m = {1:2, 3:4} for x, y in m.items(): print(x, y, end=" ")

1 2 3 4

Python features include: (1) interactive mode (2) portable (3) easy to add modules

1,2,3

Which of the following are true about Python: (1) Python is interpreted (2) Python is Object Oriented (3) Python is interactive

1,2,3

What is the output after the following? for x in range(10, 20, 2): print(x, end=" ")

10 12 14 16 18

What is the output of the following? for x in range(10, 20, 2): print(x, end=" ")

10,12,14,16,18

What is the output after the following statements?

100

What is the output after the following statements of the print. m = 2 for n in range(3, 15, 5): n += m + 2 print(n)

17

What is the output of the following?

2

What is the output of the following code? def g(n, m): if n <= 0: return m else: return g(n-1, m+1) print(g(2, 1))

3

What is the result of the following: def f(n): if n==1: return 1 else: return 2**n*f(n-1) print(f(3))

32

How many numbers will be printed? for i in (1 ,2 ,3): for j in range(0, i): print(i + j)

6

It is impossible to change any immutable collection to a mutable one with the same elements.

False

It is impossible to read an entire text file into a list of lines using one of the standard Python functions.

False

In Python, a syntax error is detected by the ________ at _________.

Interpreter/ runtime

You want to create a dictionary with K as the list of unique string keys and V as the list of unique string values.Which of the following is an impossible result?

K<V

x = {"salmon": "fish", "orca": "whale"} y = x["fish"] print(y)

KeyError ({} doesnt match [])

What is true about python 3

Python 3 is a newer version, but it is not backward compatible with Python 2.

The same syntax can be used for iterating over a list, tuple, string, set and dictionary.

True

What is the output after the following statements? x = ["Fall"] y = ["Spring", "Summer", "Winter"] z = x + y print(z)

['Fall', 'Spring', 'Summer', 'Winter']

x = list('abcdefgh') print(x[::-1][1:4])

['g',' f',' e']

What will be x_list after the following statement? x_list = [] for n in range(4): x_list.append(n**2) print(x_list)

[0,1,4,9]

What is the output after the following statements? x = [[1], 2] y = x.copy() y[0][0] = 100 print(x, y)

[[100],2] [[100],2]

The mechanism for passing parameters to a function in Python is:

call by assignment

x = 'Monday' y = x[0:4][100:500] + x[3::2]

error

What is the output of the following? def f(n): return 2*n + f(n-1) print(f(3))

f runs forever and causes StackOverflowError

What is output after the following statement? x = 1 y = 2 z = x == y print(z)

false

What is the base case for the following recursion: def f(b, q, n): if n == 0: return 0 else: return b*q**(n-1) + f(b, q, n-1) print(f(b=2, q=3, n=4))

n is 0

Arguments to functions always appear within:

parentheses: ( )

to start python from the command prompt, use the command

python

Which of the following is usually true?

recursive functions require more computer resources and more execution time, whereas non-recursive require more lines of code

What data type is used to return function results?

set

What is the data type of x? x = ("Boston University")

string

Python syntax is case sensitive

true

Which collection is immutable but could contain mutable elements?

tuple

Which of the following does not exist in Python?

tuple comprehension

Which of the following commands will create a list?

x = list() y = [] z = list([1, 2, 3])

Which statement is illegal in Python?

x = {[1] : 2, [3] : 4}

Which Python statement will add 5 to the end of list x?

x.append(5)

Which statement is illegal in Python?

y = {[1], [2]}

What Python statement allows to suspend function execution and resume it for next call(s)?

yield


Ensembles d'études connexes

Primerica (Provisions and Options)

View Set

(Chapter 44) Digestive and GI Treatment Modalities

View Set

Theology Ethics and Medicine Studyguide

View Set

History of Rock n Roll Exam #1- Glam Rock

View Set

Chapter 13: Disability Insurance

View Set

QBO exam section 1 2020 April 29th

View Set

completing the Application, Underwriting, and Delivering the policy

View Set