Final Exam Info
Final Exam Information
The exam will cover the entire semester, with the exception of Picobot. It will only include topics that we covered in class and/or on the assignments. Topics from the readings that we did not cover in class will not appear on the exam.
The exam will be held on Thursday, August 09th in our regular classroom (HAR212) 9:00-11:00am
You must bring your BU ID to the exam, and have it verified when you turn in the exam.
The exam will consist of three parts:
Part I will contain multiple-choice questions that you must complete. For each multiple-choice question, you will be able to specify up to two answers. Each question will be worth 3 points, and you will get 1 point for any problem in which your first choice is wrong but your second choice is correct. There is no penalty for specifying a wrong second choice.
Part II will consist of several multi-part problems. The individual parts of each problem will be similar in format and difficulty to the problems on the midterms. You will have some choice in this section (e.g., complete 3 out of 4 problems, or 4 out of 5).
Part III will consist of a single multi-part problem that you must complete. Parts of this problem may require a bit more work than the typical midterm problem, but they will still be doable in the time available.
You will have two hours to complete the exam. The questions will be worth a total of 100 points. You should plan on spending approximately one minute per point.
You may use one 3-inch by 5-inch index card with handwritten notes (both sides). However, you must use a card that we provide. These cards will be distributed in class. Please turn your card in with your exam.
You may not use any electronic devices during the exam.
You may not leave the exam room and return, so please use the restroom before the exam.
Preparing for the exam
One way to prepare is to review the class notes, lecture videos, and assignments, and to make a summary of the key points in your own words. “Boiling down” the material in this way is a great way to ensure that you really understand the key concepts.
We also encourage you to do practice problems. Options include:
redoing the questions posed in class–both the clicker questions and the open-response ones. The online lecture notes include both the questions and–on the next page–the answers.
the practice problems found below, which are primarily focused on material from the past month or so
a separate sheet of extra practice problems. You may ignore question 6 and 10, which cover topics we skipped in this summer session.
When working on practice problems, try to come up with your answers on paper, rather than through a trial-and-error approach on IDLE or in another programming environment. This will be give you an experience that is similar to the one that you have during the exam.
Feel free to post questions on Piazza (using the
final_examtag) or to email the course account (
Answers will be posted as we get closer to the exam.
What does the following code print?
a = [1, 2, 3, 4] b = a b = 6 print('a =', a, 'b =', b)
Using a memory diagram and a couple of sentences, explain the result printed in problem number 1.
What is printed when you invoke
def eat(x): x = 9 x = 11 def prob3(): food = [4, 5, 6, 7] eat(food) print('food =', food)
Using a memory diagram and a couple of sentences, explain the result printed in problem number 3.
Write a function
create_2dthat takes as input two integers
width, and that creates and returns a 2D list (i.e., a list of lists) with values that are the row number multiplied by the column number. For example:
>>> create_2d(3, 5) [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
Write a function
add_onethat takes an input
gridthat is a 2D list (a list of lists). Your function should add 1 to each element of
grid, but it should not return anything. For example:
>>> my_grid = create_2d(3, 5) >>> add_one(my_grid) >>> my_grid [[1, 1, 1, 1, 1], [1, 2, 3, 4, 5], [1, 3, 5, 7, 9]]
Create a Python class named
Phonebookwith a single attribute called
entries. The constructor should initialize
entriesto be a dictionary containing the following names and phone numbers:
Bob 72345, Sally 71000, John 79999. Use the names as the keys of the dictionary and the phone numbers (which you should represent as
ints) as the values.
Add a method named
Phonebookclass. It should take a parameter
nameis present in the phonebook, and
Falseotherwise. For example:
>>> book = Phonebook() >>> book.contains('Foo') False >>> book.contains('Bob') True
Write another method for your
number_forthat takes a parameter
nameand returns the phone number for
namein the called
Phonebookobject. It should return
nameis not found. Here is an example:
>>> book = Phonebook() >>> book.number_for('Sally') 71000 >>> book.number_for('foobar') -1
Hint: Consider using your
containsmethod from problem 8.
Write another method for your
add_entrythat takes as parameters a
numberand adds an appropriate entry to the phonebook. For example:
>>> book = Phonebook() >>> book.number_for('Turing') -1 >>> book.add_entry('Turing', 77777) >>> book.number_for('Turing') 77777
Create a Python class called
Triangle. The constructor for this class should take two arguments,
height, and store those values in appropriately named attributes. In addition, you should add a method called
areathat computes and returns the area of the triangle. (The area of a triangle is 0.5 times the product of its base and height.) For example:
>>> tri = Triangle(3, 4) >>> tri.area() 6.0
Add a method to your
Triangleclass that enables you print a
Triangleobject in a readable way. For example:
>>> tri = Triangle(3, 4) >>> print(tri) triangle with base 3 and height 4
Add a method to your
Triangleclass that will allow you to use the
==operator to test if two
Triangleobjects are equal–i.e., if they have the same base and height. For example:
>>> tri1 = Triangle(3, 4) >>> tri2 = Triangle(3, 4) >>> tri3 = Triangle(4, 3) >>> tri1 == tri2 True >>> tri1 == tri3 False
Write a function called
mainthat creates three triangle objects
tri1(with base 3 and height 4),
tri2(with base 6 and height 6), and
tri3(also with base 3 and height 4). The function should print the three objects and their areas. Next, it should test whether
tri2are equal and report the result. Finally, it should test whether
tri3are equal and report the result. Your function should take full advantage of the
Trianglemethods you have written. Here is the desired output:
>>> main() tri1: triangle with base 3 and height 4 (area = 6.0) tri2: triangle with base 6 and height 6 (area = 18.0) tri3: triangle with base 3 and height 4 (area = 6.0) tri1 and tri2 are not equal tri1 and tri3 are equal
Write a subclass of
EquilateralTriangle. Its constructor should take a single parameter
siderepresenting the length of a side. However, the new class should not have any new attributes. Rather, it should use the attributes that are inherited from
Triangle, and you should initialize those attributes by calling the superclass constructor and passing it the appropriate values. (You should approximate the height of the triangle as 0.866 times the side length.) For example:
>>> tri1 = EquilateralTriangle(6) >>> print(tri1) triangle with base 6 and height 5.196
Override the appropriate method in
EquilateralTriangleso that printing an
EquilateralTriangleobject produces an output that looks like the following:
>>> tri1 = EquilateralTriangle(6) >>> print(tri1) equilateral triangle with side 6