Values in a dictionary can have which of the following types?

Practice More Questions From: Quiz 5b

Q:

Which of the following expressions corresponds to a dictionary with no elements?

Q:

Given an existing dictionary favorites, what Python statement adds the key “fruit” to this dictionary with the corresponding value “blackberry”?

Q:

Keys in a dictionary can have which of the following types?

Q:

Values in a dictionary can have which of the following types?

Q:

Question 6 Conceptually, the purpose of a dictionary is to represent a relationship between two collections of data — each key in the dictionary is related to one value. Which of the following situations are instances of such a relationship?Do not include situations where you have to introduce additional information in order to fit them into such a relationship.

Q:

In the previous quiz, you were asked to complete the following code: import randomdef random_point(): “””Returns a random point on a 100×100 grid.””” return (random.randrange(100), random.randrange(100))def starting_points(players): “””Returns a list of random points, one for each player.””” points = [] for player in players: point = random_point() ??? return pointsNow, we want to rewrite starting_points using a list comprehension. Which list comprehensions could replace the following question marks?def starting_points(players): “””Returns a list of random points, one for each player.””” return ???

Q:

You have the following code. The goal is to display a portion of the image, rescaling it to fill the canvas. import simpleguiframe_size = [200, 200]image_size = [1521, 1818]def draw(canvas): canvas.draw_image(image, image_size, [image_size[0] / 2, image_size[1] / 2], [frame_size[0] / 2, frame_size[1] / 2], frame_size)frame = simplegui.create_frame(“test”, frame_size[0], frame_size[1])frame.set_draw_handler(draw)image = simplegui.load_image(“http://commondatastorage.googleapis.com/codeskulptor-assets/gutenberg.jpg”)frame.start()

Q:

We often want to loop over all the key/value pairs in a dictionary. Assume the variable my_dict stores a dictionary. One way of looping like this is as follows: for key in my_dict: value = my_dict[key] …However, there is a better way. We can instead write the following:for key, value in ???: …What code should replace the question marks so that the two forms are equivalent?

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments