Exam 13: Video Games: Multithreading, Event Handlers, Static Variables
Exam 1: Introduction to Python: Introduction to Numeric Types, Turtle Graphics, Simple for Loops and Functions34 Questions
Exam 2: Pthon: Estimating PI: Math and Random Methods, Selection and Boolean Expressions, the Print Function33 Questions
Exam 3: Codes and Other Secrets: String Operators and Methods, the Len Built-In Function, Keyword Parameters, User Input33 Questions
Exam 4: Introducing the Python Collections: Lists, Dictionaries, Tuples, and Statistics33 Questions
Exam 5: Bigger Data: File Io: the While Loop, String Formatting, Reading Online Data in CSV and Json Formats33 Questions
Exam 6: Image Processing: Nested for Loops, Functions As Parameters, Namespaces, Lists of Lists33 Questions
Exam 7: Data Mining: Cluster Analysis: More on the While Loop; Parrallel Lists31 Questions
Exam 8: Cryptanalysis: Advanced Dictionaries and Lists, Regular Expressions32 Questions
Exam 9: Fractals: the Geometry of Nature: Recursion, Grammars and Production Rules33 Questions
Exam 10: Astronomy: Creating Classes, Writing Constructors, Accessors, Mutators and Special Methods33 Questions
Exam 11: Simulation:computer Simulation Using Objects34 Questions
Exam 12: Father Was a Rectangle: Inheritance and Object-Oriented Design32 Questions
Exam 13: Video Games: Multithreading, Event Handlers, Static Variables33 Questions
Select questions type
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.
Free
(True/False)
4.9/5
(38)
Correct Answer:
False
Explain how to set up a callback for mouse events on the turtle.
Free
(Essay)
5.0/5
(42)
Correct Answer:
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.
What is the main structure of an event-driven program?
Free
(Multiple Choice)
4.7/5
(43)
Correct Answer:
A
Match each definition with its term.
-Hides any functions from outside of the class and starts with __.
(Multiple Choice)
4.7/5
(48)
Match each definition with its term.
-First-come first-served data structure.
(Multiple Choice)
4.8/5
(37)
Passing ____ to a turtle function that is used to register a callback effectively cancels the callback mechanism.
(Multiple Choice)
4.8/5
(44)
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?
(Multiple Choice)
4.8/5
(31)
Match each definition with its term.
-A special instruction to the Python interpreter that starts with @.
(Multiple Choice)
4.9/5
(35)
Describe the __moveOneStep method of the AnimatedTurtle class presented in your text. What is the significance of the two underscores in the method name?
(Essay)
4.9/5
(33)
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.
(Multiple Choice)
4.8/5
(44)
A(n) ____ variable is shared by all instances of the class.
(Multiple Choice)
4.9/5
(31)
Before using the screen to respond to keyboard events, call the ____ method of Screen.
(Multiple Choice)
4.8/5
(37)
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.
(Essay)
4.8/5
(31)
The main difference between keyboard callbacks and mouse callbacks is that the function we write to accept mouse callbacks must accept two parameters.
(True/False)
4.9/5
(45)
To hide a function from use outside of the class, begin the name with:
(Multiple Choice)
4.8/5
(28)
Showing 1 - 20 of 33
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)