Quiz 5 Information
Quiz details
-
Quiz 5 will be held on Wednesday 8/7/24, during the 6-hour window of 15:00 - 21:00 EDT
- Boston (EDT): 3pm-9pm EDT
- China: Thursday 8/8/24 3am-9am
- UTC (UK time): 19:00-1:00 (+1 day)
-
You will have 30 minutes for the quiz including writing your answers and submission.
-
There are some sample/pratice questions at the bottom of this page. You will need to determine and write the answer(s) 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 examples from class or problem sets.
Quiz Logistics
-
The quiz will be conducted in the context of Gradescope. We will use the “online quiz” feature of Gradescope, in which you will type all of your answers directly into boxes within the web browser.
-
You may use blank scratch paper in preparing your answers to quiz questions, but you will type your final responses into Gradescope.
-
If you encounter technical errors with Gradescope during the quiz: write your answers on plain paper, scan the pages, and email them to Aaron (azs@bu.edu) as evidence of your work.
-
You may not use Spyder or any other Python tools to write, test, debug, or evaluate any code.
-
You may not use ChatGPT or any similar AI tools to write solutions for this quiz. We reserve the right to do a live oral exam with anyone suspected of using AI tools.
-
You should take the quiz by yourself in a quiet room, without assistance from others and without using resources of any kind. Although we cannot prevent you from consulting other resources, attempting to do so will likely cause you to run out of time. Moreover, the final exam will have a live proctor; if you cannot solve the problems on your own on the quizzes, you will not be successful for the final exam.
-
As this will be an independent quiz, the course staff is not available to help you with questions about the quiz during real-time. If you have questions or concerns during the quiz, write your questions or any assumptions clearly on you answer page, and we can discuss during office hours.
-
Aside from the machine on which you are reading the quiz, you must turn off and put away all other electronic devices including your phone.
-
You may not communicate with anyone during the quiz. You must not discuss the quiz with classmates until the entire quiz window is closed. Any discussion creates an unfair advantage to students who take the quiz a later time.
We reserve the right to conduct a separate one-on-one oral examination with any student to verify the student’s understanding of the material.
Material covered
The quiz will focus on the material that we have discussed in class during Week 5, modules 9 and 10.
You must be familiar with concepts that were introduced in the pre-class videos, in-class discussion, or on the problem sets that were not covered in the videos or readings.
Preparing for the quiz
-
One way to prepare is to review the videos and readings and class notes and make a summary of the key points in your own words. “Summarizing” 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 problems from the problem sets
-
additional practice problems (below)
-
-
When working on practice problems, try to come up with your answers on paper, rather than through a trial-and-error approach in Spyder 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 about the quiz on Piazza (using the
quiz5
tag).
Additional practice problems
-
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
. The constructor should initializeentries
to 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 asint
s) as the values. -
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('Foo') False >>> book.contains('Bob') 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 return-1
ifname
is not found. Here is an example:>>> book = Phonebook() >>> book.number_for('Sally') 71000 >>> book.number_for('foobar') -1
Hint: Consider using your
contains
method from problem 8. -
Write another method for your
Phonebook
class calledadd_entry
that takes as parameters aname
and anumber
and 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