Quiz 8

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Given the following Python code, what should you place in the blank to sum the total snowfall for the week? daily_inches_of_snow = [1, 2, 5, 11, 7, 3, 12] _____ print("The total snowfall for the week is: " + total + "inches.")

total = 0 for element in daily_inches_of_snow: total += element

When creating a Python dictionary, _____.

you must provide three items for each entry, separated by colons

A list index is a random number that identifies the contents of the list element.

No

A list can be used to manipulate the characters in a word or phrase by reversing them or encrypting them.

True

Conceptually, two-dimensional lists appear to be tables, grids, or matrices.

True

The following Python code will successfully initialize a two-dimensional list called paintBox. paintBox = [["Red", "Orange", "Yellow"], ["Green", "Blue", "Violet"]]

True

To determine how many times a certain value appears in a Python list, you can iterate over the list using an accumulator to record the number of times the target element appears or you can call the count() method on the list.

True

Which statement is true concerning the following two Python code blocks? Code block A: listOfInts = [i for i in range(5, 26, 5)] Code block B: listOfInts = [] for i in range(5, 26, 5): listOfInts.append(i)

a. Code blocks A and B result in the same data being stored in listofinit

Which Python statement should you use to declare an empty list named bucket in Python?

a. bucket = []

The following Python code creates a dictionary called marbles and then _____. marbles = {"Red": 10, "Tiger eye": 3, "Blue": 8, "Green": 5} marbles["Green"] = 6

a. changes the value associated with the key "Green" to 6

Which Python statement correctly initializes a dictionary data structure?

a. positions = {"Chad": "1st base", "Cindy": "2nd base", "Tim": "Outfield"}

What should you place in the blank in the Python code below if you want to display the price for the cat figurine? figurinePrices = {"dog": 3.55, "cat": 4.15, "dolphin": 5:65, "turtle": 4.25} print(_____)

b. "The cat costs", figurinePrices["cat"]

Which Python statement should be used to declare and initialize a one-dimensional numeric list?

b. kites_sold = [8, 15, 12, 7, 3, 5, 5]

Given the following program code, what is the output value? numbers = [1024, 1167, 956, 690, 1307, 1672, 1102] print(numbers[6])

c. 1672

Which statement will add a new key, "Unit 5", and its associated value, "Josip", to the Python dictionary called residents? residents = {"Unit 1": "Marley", "Unit 2": "Bruce", "Unit 3": "Ramesh", "Unit 4": "Ivy"}

c. residents["Unit 5"] = "Josip"

Suppose you create a Python list containing the elements "J", "A", "W", "S", and 3, in that order. What are the index values of the first and last elements of this list?

d. 0 and 4

What belongs in the blank in the following Python code if your goal is to use both mapping and filtering together to create doubleTrouble? doubleTrouble = [_____ if i % 2 == 0]

doubleTrouble = list(map(lambda i: i * 2, filter(lambda i: i % 2 == 0, your_list)))

What should you place in the blank in the following Python code to achieve the output shown? weekendSpecials = {"Friday": "salmon", "Saturday": "grouper", "Sunday": "cod"} _____ Output: The special on Friday is salmon The special on Saturday is grouper The special on Sunday is cod

for key in weekend_specials.keys(): print("The special on", key + " is", weekend_specials[key])

What Python code belongs in the blank to obtain the output shown by traversing gameOutcomes? gameOutcomes = ["Win", "Loss", "Loss", "Win", "Win"] _____ Output: Win Loss Loss Win

for outcome in gameOutcomes: print(outcome)

Which variable represents a Python dictionary?

name: favoritePie, data: "John": "apple", "Laura": "blackberry"


Set pelajaran terkait

Geometrie - základní pojmy - PJ

View Set

Hypothermia in Newborn/Fever in Child

View Set

Laws of Definite Proportions & Multiple Proportions

View Set

World History Semester 2 Study Guide

View Set

Sociology Chapter 1 : the Sociological Perspective

View Set

Microbiology 220 Mrs. Bradley Unit 1

View Set

Conversion, Obversion, Contraposition

View Set

Chapter 14: The Brain and Cranial Nerves

View Set