Quiz 8#

Question 1#

Which of the following is valid notation for a set in CodeSkulptor ?

set()
set([])
{} \


{} is a dict. Others are sets.


Question 2#

Which of the following operations can mutate set s? You may want to try some examples in CodeSkulptor and refer to the documentation .

t.symmetric_difference_update(s)
t.intersection(s)
s.intersection(t)
s.update(s)
s.remove(x)
s.symmetric_difference_update(t) \


s.update(s)
s.remove(x)
s.symmetric_difference_update(t)


Question 3#

Which operation corresponds to the following description? Refer to the CodeSkulptor documentation .

Given two sets, s and t we want a new set containing all the elements that are in one of the sets, but not both of the sets. For example, if s has the elements 1, 2, 3, 4, and t has the elements 3, 4, 5, 6, then the result should have the elements 1, 2, 5, 6.

t.difference_update(s)
s.difference(t)
s.difference_update(t)
s.symmetric_difference(t) \


s.symmetric_difference(t) \


Question 4#

A set is an unordered collection of distinct elements. Which of the following problem contexts represent instances of this idea?

Names for everyone taking this course
Alphabetized names
Group of distinct cities \


Group of distinct cities \

Names for everyone taking this courser => we could also have same names for different people. Probably we do not want to have one object for multiple students.


Question 5#

How many frames per second are typically projected in modern movies? How many times per second is the draw handler typically called in CodeSkulptor?

Enter two numbers representing these frame rates in frames per second. Use only spaces to separate the numbers.

Enter answer here:\


24 60


Question 6#

For this week, the mini-project defines and uses a Sprite class to support animations. What attribute (also known as a field) can be used to help index the sub-images forming an animated sprite? (If you are stuck, review the bonus phase in the mini-project description.)

pos
image_center
radius
image
image_size
sound
animated
angle_vel
lifespan
angle
age \


age probably stores the time after the creation of the sprite, so it is useful for picking the right tile.


Question 7#

Consider a horizontally-tiled image where each sub-image has the same size. If each sub-image is of size 60×90 (in pixels), what is the horizontal distance (in pixels) between the centers of adjacent sub-images?

180
120
60
90 \


60


Question 8#

How many distinct numbers are printed by the following code? Enter the count.

def next(x):
    return (x ** 2 + 79) % 997

x = 1
for i in range(1000):
    print x
    x = next(x)

Hint: Consider how editing the code to use a set could help solve the question.

Enter answer here:\


46

def next(x):
    return (x ** 2 + 79) % 997

x = 1
s = set()
for i in range(1000):
    s.add(x)
    x = next(x)
print(len(s))

Question 9#

Which instructor exhibits the best coding style?

Scott
Joe
John
Stephen \


John - he has very helpful programming tips.