CMU 15-112 Summer 2020: Fundamentals of Programming and Computer Science
Collab 3 (Due Thu 19-May, at 11:59pm)
- This assignment is COLLABORATIVE. This means you may work with your week's collaboration group within the course collaboration boundaries. See the syllabus for details.
- To start:
- Create a folder named 'collab3'
- Download collab3.py and cs112_m20_day3_linter.py to that folder
- Edit collab3.py using VSCode
- When you are ready, submit collab3.py to Autolab. For this hw, you may submit up to 20 times (which is way more than you should require), but only your last submission counts.
- Do not use lists or recursion in this assignment.
- Do not hardcode the test cases in your solutions.
- mostFrequentLetters(s) [25pts]
Write the function mostFrequentLetters(s), that takes a string s, and ignoring case (so "A" and "a" are treated the same), returns a lowercase string containing the letters of s in most frequently used order. (In the event of a tie between two letters, follow alphabetic order.) So:mostFrequentLetters("We Attack at Dawn")
returns "atwcdekn". Note that digits, punctuation, and whitespace are not letters! Also note that seeing as we have not yet covered lists, sets, maps, or efficiency, you are not expected to write the most efficient solution. (And you should not use lists, sets, or maps in your solution. Do not use sorted() or .sort() either.) Finally, if s does not contain any alphabetic characters, the result should be the empty string (""). - bestStudentAndAvg(gradebook) [25 pts]
Background: for this problem, a "gradebook" is a multiline string where each row 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 bestStudentAndAvg(gradebook), that takes a gradebook and finds the student with the best average (ignoring the case where there is a tie) and returns a string of that student's name followed by a colon (":") followed by his/her average (rounded using the provided roundHalfUp). For example, here is a test case:gradebook = """ # ignore blank lines and lines starting with #'s wilma,91,93 fred,80,85,90,95,100 betty,88 """ assert(bestStudentAndAvg(gradebook) == "wilma:92"))
Note: you most likely will want to use both s.split(",") and s.splitlines() in your solution.