CMU 15-112 Spring 2019: Fundamentals of Programming and Computer Science
Lab 3 (Due as part of hw3 on Sunday 3-Feb, at 5pm)
Due to the Polar Vortex CMU shutdown, we'll be holding recitation during the lab slot on Friday. You may complete the lab problems collaboratively or solo at whatever time you want.
- Reminder: Lab problems must be solved collaboratively with at least one other student. List your collaborators!
- Do not complete these problems before your scheduled lab on Friday; we'll just make you work on them again with another student, or you won't get the lab attendance credit.
- You should put the solutions to these problems in your hw3.py file. Follow these steps if you haven't started yet!:
- Create a folder named 'week3'
- Download both hw3.py and cs112_s19_week3_linter.py and hw3_files.zip to that folder. Unzip hw3_files.zip in the folder.
- Edit hw3.py using Pyzo
- Do not use lists, list indexing, sets, dictionaries, or recursion this week.
- Do not hardcode the test cases in your solutions.
- Your hw3 file should contain answers to these problems (25pts) plus the hw3 problems released earlier this week (75pts)
- COLLABORATIVE Code Writing: gradebookSummary(gradebookFilename) [15 pts]
For this problem, we'll assume that gradebooks are stored in .txt files. Each row of the gradebook file contains a student's name (one word, all lowercase), followed by one or more comma-separated integer grades. A gradebook always contains at least one student, and each row always contains at least one grade. Gradebooks can also contain blank lines and lines starting with the "#" character, which should be ignored.
With this in mind, write the function gradebookSummary(gradebookFilename) that takes the filename of a gradebook as an argument and returns a summary of the gradebook as a string. This summary string should show each student followed by a tab followed by their average grade (rounded to the hundreth place). The summary string should have the students listed in their original order (separated by newlines, but without a newline at the end), but should get rid of any comments or blank lines.
For example, here is a test case:
# the following string is the content of the file gradebook1.txt """# ignore blank lines and lines starting with #'s wilma,91,93,94 fred,80,85,90,97,100 betty,88""" assert(gradebookSummary("gradebook1.txt") == "wilma\t92.67\nfred\t90.40\nbetty\t88.00"))
Hint: You may wonder how to locate and distinguish the name on each gradebook line from the scores... one approach would be to look for the first comma after a newline.
(Note: If you think you know an easy way to solve this problem but the linter bans your solution, it's probably because you're using a concept we haven't taught yet!) - COLLABORATIVE Code Writing: applyCaesarCipher(message, shiftNum) [10 pts]
A Caesar Cipher is a simple cipher that works by shifting each letter in the given message by a certain number. For example, if we shift the message "We Attack At Dawn" by 1 letter, it becomes "Xf Buubdl Bu Ebxo".
Write the function applyCaesarCipher(message, shiftNum) which shifts the given message by shiftNum letters. You are guaranteed that message is a string, and that shiftNum is an integer between -25 and 25. Capital letters should stay capital and lowercase letters should stay lowercase, and non-letter characters should not be changed. Note that "Z" wraps around to "A". So, for example:
assert(applyCaesarCipher("We Attack At Dawn", 1) == "Xf Buubdl Bu Ebxo") assert(applyCaesarCipher("zodiac", -2) == "xmbgya")
Collaborative lab problems
If you finish early, consider working on the collaborative problem mostFrequentLetters from hw3.