print(list(range(1,5)))
[1, 2, 3, 4]
What is the import statement for:
x = random.randrange(5)
import random
list(range(10, 12, -2))
[]
In an UML diagram how do you indicate Containment (Aggregation).
diamond
When other is used as a parameter, it commonly refers to what is on the right hand side of the operator. (True/False)
True
What parameters would you use for range to simulate all the numbers that are on a standard 6-sided dice?
(1,7)
How do you create a turtle object named tess?
tess = Turtle()
What code allows the programmer to handle an exception so that python doesn't crash?
try except
Which method do you call when you use constructor chaining and how do you do it?
super().__init__
The parents constructor
What does polymorphism mean?
many shapes
print(list(range(3,9,3)))
[3, 6]
What is the constructor method called in python?
__init__
What is the difference between an alias and a clone?
Alias ->Multiple variables that contain references to the same object.
Clone->To create a new object that has the same value as an existing object.
Give an 3 examples of inheritance (parent<-child) from frogger and/or asteroids.
Movable<-Rotatable<-Polygon<-Ship
etc.
What is duck typing? Give an example from Assignments this semester.
If all of the operations inside the function can be applied to the type, the function can be applied to the type.
hits(), evolveAllObjects, evolve, draw, etc.
longer_list = [1,2]
longer_list = longer_list.append(3)
print(longer_list)
None
Modularity is the ability to take code, encapsulate it so it can be used it in other places. Give 3 advantages to modularity.
1. code reuse
2. code testing
3. code maintainability.
What is the quickest way to find semantic errors? The long way is to step through the debugger.
Use print statements
What is deep copy?
To copy the contents of an object as well as any embedded objects, and any objects embedded in them, and so on
In operator overloading, give an example of a method that is required to return self.
__iadd__, __imul__, +=, *=
color_tuple = (183,27,27) #red
color_tuple[1] = 183 # add more to green
print(color_tuple)
TypeError
What is Built-in scope? Give an example.
refers to all the identifiers built into Python(ex: range, sum, min, max)
Create a copy of a_list called b_list
b_list = a_list[:]
I1 = Inventory(3)
b = Bicycle(7,25)
I1.add_bike(b)
I2 = deepcopy(I1)
How many bicycle objects will be stored in memory after this code is run?
2
Why would we have the __add__ method call __iadd__?
All of the math is done in __iadd__ so it can all be updated/fixed in one place.