Filters
Question type

Study Flashcards

Match each definition with its term. -First-come first-served data structure.


A) Queue
B) Static variable
C) Decorator
D) Name mangling

E) None of the above
F) B) and D)

Correct Answer

verifed

verified

Case Study 2: 1. import turtle 2. 3. class Etch: 4. def __init__(self): 5. self.__myT = turtle.Turtle() 6. self.__myScreen = turtle.Screen() 7. self.__myT.color('blue') 8. self.__myT.pensize(2) 9. self.__myT.speed(0) 10. self.__distance = 5 11. self.__turn = 10 ... 19. def fwd(self): 20. self.__myT.forward(self.__distance) -Refer to the session in the accompanying Case Study 2. The Etch class uses the inheritance approach to working with a turtle.

A) True
B) False

Correct Answer

verifed

verified

False

To hide a function from use outside of the class, begin the name with:


A) an x.
B) one underscore.
C) two underscores.
D) one "at" symbol.

E) A) and B)
F) A) and C)

Correct Answer

verifed

verified

Match each definition with its term. -Hides any functions from outside of the class and starts with __.


A) Queue
B) Static variable
C) Decorator
D) Name mangling

E) B) and D)
F) None of the above

Correct Answer

verifed

verified

What is the main structure of an event-driven program?


A) Event loop
B) Queue
C) Callback function
D) Event processing

E) A) and B)
F) A) and D)

Correct Answer

verifed

verified

A

Passing ____ to a turtle function that is used to register a callback effectively cancels the callback mechanism.


A) stop
B) None
C) 0
D) turtle

E) B) and C)
F) None of the above

Correct Answer

verifed

verified

What is the name of the event loop for a turtle?


A) run
B) main
C) mainloop
D) eventloop

E) B) and C)
F) A) and B)

Correct Answer

verifed

verified

A(n) ____ variable is shared by all instances of the class.


A) instance
B) multithreaded
C) event
D) static

E) A) and B)
F) C) and D)

Correct Answer

verifed

verified

Before using the screen to respond to keyboard events, call the ____ method of Screen.


A) listen
B) onkey
C) main
D) start

E) None of the above
F) All of the above

Correct Answer

verifed

verified

Match each definition with its term. -A special instruction to the Python interpreter that starts with @.


A) Queue
B) Static variable
C) Decorator
D) Name mangling

E) All of the above
F) None of the above

Correct Answer

verifed

verified

How do you make a class multithreaded in Python?


A) Inherit from Thread.
B) Import threading.
C) Include an instance variable named thread.
D) Include a method named threaded() .

E) All of the above
F) A) and B)

Correct Answer

verifed

verified

The main difference between keyboard callbacks and mouse callbacks is that the function we write to accept mouse callbacks must accept two parameters.

A) True
B) False

Correct Answer

verifed

verified

How would you detect when two turtles collide?

Correct Answer

verifed

verified

To calculate the approximate distance be...

View Answer

Typically, desktop applications are single-threaded.

A) True
B) False

Correct Answer

verifed

verified

Case Study 2: 1. import turtle 2. 3. class Etch: 4. def __init__(self): 5. self.__myT = turtle.Turtle() 6. self.__myScreen = turtle.Screen() 7. self.__myT.color('blue') 8. self.__myT.pensize(2) 9. self.__myT.speed(0) 10. self.__distance = 5 11. self.__turn = 10 ... 19. def fwd(self): 20. self.__myT.forward(self.__distance) -Refer to the session in the accompanying Case Study 2. Explain the composition approach used by the Etch class.

Correct Answer

verifed

verified

Composition is a style of object-oriente...

View Answer

Match each definition with its term. -Variable that is shared by all instances of a class and is available to all the methods in the class.


A) Queue
B) Static variable
C) Decorator
D) Name mangling

E) B) and C)
F) C) and D)

Correct Answer

verifed

verified

Explain how to set up a callback for mouse events on the turtle.

Correct Answer

verifed

verified

To set up a callback for a mouse click, we call the onclick method and simply pass it the function to call whenever the mouse is clicked. The main difference between the keyboard callbacks and the mouse callbacks is that the function we write to accept mouse callbacks must accept two parameters. The two parameters will specify the x and y coordinates of where the cursor was when the mouse was clicked.

Describe the __moveOneStep method of the AnimatedTurtle class presented in your text. What is the significance of the two underscores in the method name?

Correct Answer

verifed

verified

The __moveOneStep method checks to see i...

View Answer

Case Study 1: 1. class EventHandler: 2. def __init__(self) : 3. self.__queue = [] 4. self.__eventKeeper = {} 5. 6. def addEvent(self, eventName) : 7. self.__queue.append(eventName) 8. 9. def registerCallback(self, event, func) : 10. self.__eventKeeper[event] = func 11. 12. def run(self) : 13. while(True) : 14. if len(self.__queue) > 0: 15. nextEvent = self.__queue.pop(0) 16. self.__eventKeeper[nextEvent]() 17. else: 18. print('queue is empty') -Refer to the session in the accompanying Case Study 1. What kind of loop is shown on lines 13-18?


A) Definite
B) Abstract
C) Multithreaded
D) Infinite

E) C) and D)
F) All of the above

Correct Answer

verifed

verified

What are some of the benefits of extending a class from Thread?

Correct Answer

verifed

verified

By inheriting from Thread, we gain acces...

View Answer

Showing 1 - 20 of 33

Related Exams

Show Answer