Quiz 4 Info
Quiz 4 Information
Quiz details

Quiz 4 will be held on Thursday, August 1st.

The quiz will be held at the start of class at 9:009:35am

We will continue the class as usual after the quiz.

You must bring your BU ID to the quiz, so that we can check it when you turn in your quiz.

You will have the 35 minutes for the quiz.

You may not use any electronic devices during the quiz.

Once you leave the quiz room, you may not return, so please use the restroom ahead of time.

The quiz will include questions similar to the ones posed in class – both the Top hat questions and the openresponse ones. However, these questions will not be multiplechoice. You will need to determine and write the answer without a list of options to choose from.

In addition, there will be questions that ask you to write a function or a short program, similar to the problems from the homework.
Material covered
The quiz will focus on the material that we have discussed in class from the beginning of the summer session through Tuesday, July 31st. This corresponds to the following readings:

from CS for All:
 Chapter 6: Sections 6.1, 6.2, 6.3, 6.4, 6.5 and 6.6 of our textbook, “CS For All.”
Note: You are not responsible for details from the case studies in the readings (e.g., the information about how sorting works). However, you are responsible for the programming and problemsolving concepts that those case studies were used to illustrate.
In addition, you should be familiar with concepts that were introduced in the preclass videos, inclass discussion, or on the homeworks that were not covered in the readings.
Preparing for the quiz

One way to prepare is to review the readings and lecture notes and 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 (see below).
When working on practice problems, try to come up with your answers on paper, rather than through a trialanderror 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 quiz.

Feel free to post questions on Piazza (using the
quiz4
tag) or to email the course account (vranjbar@bu.edu
).
Additional practice problems
Answers will be posted as we get closer to the quiz.

Create a Python class called
Triangle
. The constructor for this class should take two arguments,base
andheight
, and store those values in appropriately named attributes. In addition, you should add a method calledarea
that 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
Triangle
class that enables you print aTriangle
object in a readable way. For example:>>> tri = Triangle(3, 4) >>> print(tri) triangle with base 3 and height 4

Add a method to your
Triangle
class that will allow you to use the==
operator to test if twoTriangle
objects 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
main
that creates three triangle objectstri1
(with base 3 and height 4),tri2
(with base 6 and height 6), andtri3
(also with base 3 and height 4). The function should print the three objects and their areas. Next, it should test whethertri1
andtri2
are equal and report the result. Finally, it should test whethertri1
andtri3
are equal and report the result. Your function should take full advantage of theTriangle
methods 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

Create a Python class named
Phonebook
with a single attribute calledentries
. Begin by including a constructor that initializesentries
to be an empty dictionary. 
Next add a method called
add_entry
that takes a string representing a person’s name and an integer representing the person’s phone number and that adds an entry to thePhonebook
object’s dictionary in which the key is the name and the value is the number. For example:>>> book = Phonebook() >>> book.add_entry('Turing', 6173538919)

Add a method named
contains
to yourPhonebook
class. It should take a parametername
and returnTrue
ifname
is present in the phonebook, andFalse
otherwise. For example:>>> book = Phonebook() >>> book.contains('Turing') False >>> book.add_entry('Turing', 6173538919) >>> book.contains('Turing') True

Write another method for your
Phonebook
class callednumber_for
that takes a parametername
and returns the phone number forname
in the calledPhonebook
object. It should return1
ifname
is not found. Here is an example:>>> book = Phonebook() >>> book.add_entry('Turing', 6173538919) >>> book.add_entry('Hopper', 6174951000) >>> book.number_for('Turing') 6173538919 >>> book.number_for('Hopper') 6174951000 >>> book.number_for('Codd') 1
Hint: Consider using your
contains
method from problem 7!