Several keys on the keyboard, such as Shift, CapsLock, and Ctrl, typically act to modify what happens when you press other keys, rather than doing anything on their own. When using the SimpleGUI keydown handler, how are such keys treated?

Practice More Questions From: Quiz 4a

Q:

A ball with velocity \color{red}{\verb|[4, 2]|}[4, 2] reflects off a vertical wall. What is its new velocity?

Q:

Which of the following illustrate how to properly structure a keydown or keyup event handler? (For more advanced Python programmers, assume that you have just imported simplegui and haven’t used from.)

Q:

Assume you have a program with a keydown handler. You run it, and press a single key and hold it down continuously. How many times does the keydown handler get called?

Q:

Several keys on the keyboard, such as Shift, CapsLock, and Ctrl, typically act to modify what happens when you press other keys, rather than doing anything on their own. When using the SimpleGUI keydown handler, how are such keys treated?

Q:

In Python, [1, 2, 3] is of type list. What is the name of the type of (1, 2, 3)?

Q:

Which of the following types of data are immutable in Python?

Q:

Which of the following functions must include aglobal point|}global point declaration in order to change the global variable point? point = [0, 0]def function1(): point[0] += 1 point[1] += 2def function2(): point = [50, 50]

Q:

In our program, the variable position represents a 2D position on the canvas. We want to be able to change the position by some amount in variable delta. Why is the following code snippet incorrect? position = [50, 50]delta = [1, -2]…position = position + deltaNote that the ellipses represent that we might have code in between what is shown, but such code is irrelevant and omitted.

Q:

Convert the following specification into code. Do the point and rectangle ever overlap? A point starts at [10, 20]. It repeatedly changes position by [3, 0.7] — e.g., under button or timer control. Meanwhile, a rectangle stays in place. Its corners are at [50, 50] (upper left), [180, 50] (upper right), [180, 140] (lower right), and [50, 140] (lower left).To check for overlap, i.e., collision, just run your code and check visually. You do not need to implement a point-rectangle collision test. However, we encourage you to think about how you would implement such a test.

Q:

Assume we are using acceleration control for a spaceship in a game. That is, we regularly have the following updates: .The position is incremented by the time interval multiplied by the velocity. This happens on each draw event. .The velocity is incremented by the time interval multiplied by the acceleration. This happens on each draw event. .The acceleration is periodically incremented by some fixed vector (the same vector for each step). This could happen on keyboard or timer events..Assume that, initially, the ship is stationary and subject to no acceleration. What sort of trajectory will the spaceship fly in?

Q:

Consider the following program. a = [“green”, “blue”, “white”, “black”]b = ac = list(a)d = ca[3] = “red”c[2] = a[1]b = a[1 : 3]b[1] = c[2]At the end of this code, to how many list objects do the variables refer?If you run the code and print the variables’ values, you can begin to answer this question. After all, if two variables print differently, they certainly can’t refer to the same object. However, if two variables print the same, you still need to determine whether they refer to the same object. One way is to step through the code while drawing reference diagrams. Another is to mutate one and see if others also mutate.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments