lab10 : Review for Final (optional)
|lab10||true||Review for Final (optional)||Tue 06/05 12:30PM||Fri 06/08 05:00PM|
This lab is a review of concepts from the course so far, and preparation for the final exam.
This lab may be done solo, or in pairs.
Before you begin working on the lab, please decide if you will work solo or with a partner.
- You MUST add your partner on Gradescope when submitting your work EACH TIME you submit a file(s). After uploading your file(s) on Gradescope, there is a “Group Members” link at the bottom (or “Add Group Member” under “Groups”) where you can select the partner you are working with. Whoever uploaded the submission must make sure your partner is part of your Group. Click on “Group Members” -> “Add Member” and select your partner from the list.
Once you and your partner are in agreement, choose an initial driver and navigator, and have the driver log into their account.
In this lab, you will need to create two files:
- lab10.py - file containing function definitions
- lab10_tests.py - file containing test cases. You are encouraged (though not required) to write 3 - 5 (or more) additional tests per function to confirm your code works as expected. This will not be checked by the grader, but it is good practice for the final exam—you will be expected to know how to write test cases on the final exam. You can see for yourself whether your test cases are working.
- Please add a comment with you and your partner’s name (if applicable) at the top of each file.
Starter code is provided for you and is located at the files below (you may need to refresh the page if the links do not load immediately):
For most of the functions the started code and the tests will be enough for you to know what code you are supposed to write.
For the function midi2freq, some additional explanation, provided below, will be needed.
You will complete the portions in the starter code by doing the following:
- Create a directory called ~/cs20/lab10 (using the
cdinto that directory.
idle3(you might try
idle3 &if you want to be able to type commands on your terminal window after IDLE opens).
- Use “New File” to create empty files called
- ONE AT A TIME, copy the function definitions from the starter code, write tests that go along with those functions in
lab10_tests.py, and get your tests to pass.
- Before you move on to the next function definition and its tests, get all of the tests you just wrote to pass.
- Repeat this until you have ALL of the function definitions and their tests, and all of them pass.
You are encouraged to try submitting to Gradescope periodically for several reasons:
- You can get partial credit if some of your tests pass for some of your functions.
- You will have a backup of your file in case you accidentally delete yours, or in case your laptop dies.
- You can move code between your laptop and CSIL by downloading your submitted code from Gradescope
For electronic musical instruments (for example, keyboards), each key on the keyboard is assigned a particular “midi number”, an integer corresponding to the numbers on the illustration shown here:
(adapted from an article by Joe Wolfe, University of New South Wales)
Each note on an instrument has a certain frequency, with notes to the right having higher frequencies, and notes to the left having lower frequencies. When instruments are tuned in the usual way*, the formula to convert from a midi number m to a frequency f is expressed as follows in math notation:
Your job when writing the definition for
midi2freq is to write a Python function that computes this value. This formula is value when $m$ is an integer between 0 and 127 (inclusive).
* For the music geeks, A=440Hz, equal temperament.
lab10_tests.py to Gradescope.
Once you’re done with writing your functions, navigate to the Lab assignment lab10 on Gradescope and upload your
Remember to add your name, and your partner to Groups Members for this submission on Gradescope if applicable. At this point, if you worked in a pair, it is a good idea for both partners to log into Gradescope and see if you can see the uploaded files for lab10.