Week 4 - Lists, keyboard input, the basics of modeling motion discussion
Week 4 - Lists, keyboard input, the basics of modeling motion discussion#
Learn the basics of lists in Python
Model moving objects in Python
Recreate the classic arcade game “Pong”
Week 4a - Basics of Lists#
listis a sequence type. What could be a sequence type?
Which functions do you know which work on lists?
Which operation can we do on lists but cannot do on strings?
How many events happen if you type
helloon your keyboard?
Which handlers exist for keyboard events?
The key code of most letters on our keyboard seem to correspond to the ASCII encoding. But how can we get the keycode for the arrow keys on our keyboard?
You press a key and do not release it for ten seconds. You have a timer which runs every second and prints the status of your key. How many times is the handler for the keydown event is called?
Where will the point at
(1, 2)will be after two seconds if this point moves with a velocity of
(2, 3)and its position is updated ten times per second?
What do we get if we subtract from one point another point?
Collisions and Reflections#
How would you calculate the distance between the points
Which Python operators would you use to compute the previous result?
Imagine you have a ball with a radius
r. How would you check if the ball hit the left wall or not?
What happens with the velocity of a ball if this vector is reflected by the left wall?
Week 4b - Keyboard Control#
Joe shows an example in which he has to mash the the arrow keys to move the ball. What can we do to attain a continous motion without mashing a keyboard key?
What is the problem with the control scheme implemented in this example where we change the velocity of the object everytime we press a key? How can we solve this problem?
Visualizing Lists and Mutation#
Which operator can we use to test if two variables are pointing to the same thing?
a = [0, 1]does
b = list(a)create a new list?
In the following example, how does the global list variable get modified even we do not declare it as
a = [1, 2, 3] def modify() a = 0
Programming Tips - 4#
Which datatypes are mutable and which are not?
What is the difference between tuples and lists?
When would you use tuples instead of lists?
Mini-project #4 - Pong#
Code Clinic Tips#
If you do not understand Tip #4, look at this forum thread