Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON MULTIPLE CHOICE 1a) What is the output of the following code snippet? fibonacci = {1, 1, 2, 3, 5, 8} primes = {2, 3,

PYTHON MULTIPLE CHOICE 1a) What is the output of the following code snippet?

fibonacci = {1, 1, 2, 3, 5, 8} primes = {2, 3, 5, 7, 11} both = fibonacci.union(primes) print(both) 
{1, 2, 3, 5, 8} 
{1, 2, 3, 5, 7, 8, 11} 
{2, 3, 5} 
{} 

1b) What is stored in x at the end of this code segment?

primes = {2, 3, 5, 7} odds = {1, 3, 5, 7} x = primes.intersection(odds) 
{} 
{1, 2} 
{3, 5, 7} 
{1, 2, 3, 5, 7} 

1c) Which of the following statements creates a duplicate copy of the favoriteFoodsdictionary?

favoriteFoods2 = copy(favoriteFoods) 
favoriteFoods2 = dict(favoriteFoods) 
favoriteFoods2 = duplicate(favoriteFoods) 
favoriteFoods2 = favoriteFoods 

1d) You use______________ to delete an element from a dictionary.

the remove method

the erase method

the delete method

the del statement

1e) Consider the following dictionary:

favoriteFoods = {"Peg": "burgers", "Cy": "hotdogs", "Bob": "apple pie"} 

What statement will print Peg's favorite food?

print("Peg's favorite food is: ", favoriteFoods.get(1)) 
print("Peg's favorite food is: ", favoriteFoods(Peg)) 
print("Peg's favorite food is: ", favoriteFoods["Peg"]) 
print("Peg's favorite food is: ", favoriteFoods[1]) 

1f) The_________method returns a randomly selected key-value pair from a dictionary.

pop() 
random() 
popitem() 
rand_pop() 

1g) The_______________function returns the number of elements in a dictionary:

size() 
len() 
elements() 
count() 

1h) The ________ method returns the value associated with a specified key and removes that key-value pair from the dictionary.

pop() 
random() 
popitem() 
rand_pop() 

1i) The ______ method returns all of a dictionarys keys and their associated values as a sequence of tuples.

keys_values() 
values() 
items() 
get() 

1j) Which statement correctly creates a dictionary for converting numbers 1 through 5 to roman numerals?

numerals = {[1, "I"], [2, "II"], [3, "III"], [4, "IV"], [5, "V"]} 
numerals = [1: "I", 2: "II", 3: "III", 4: "IV", 5: "V"] 
numerals = (1: "I", 2: "II", 3: "III", 4: "IV", 5: "V") 
numerals = {1: "I", 2: "II", 3: "III", 4: "IV", 5: "V"} 

1k) What is the difference between a list and a dictionary?

a list is a subset of a dictionary

a dictionary can access elements by position

a list stores individual elements but a dictionary stores key/value pairs
list operations are much faster than the equivalent dictionary operations

1l) What is returned by a dictionary's items method?

A list of integers
A sequence of tuples
A set of floating point numbers
A string

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Define treatment and error.

Answered: 1 week ago

Question

Classify delivery styles by type.

Answered: 1 week ago