CS 100

Logo

Scientific Computing

HW 7

Download and save the file hw07.py to your CS100/hw folder.

This file is a template. It contains some code there for you. Put your name at the top of the file. The questions are written in comments. Each question involves you implementing a function below it to solve a specific problem.

I suggest you work one question at a time. Read the question description and write your solution. Before you move on, test that your solution is correct by uncommenting all lines of code which call the function at the bottom of the program.

When you have questions about the homework, are looking for ideas on how to start, etc., please join office hours for either of the zone interns.

Expected output

Check your work. If it doesn’t match, look at the function call and your function implementation to see what’s going on. You can also use the debugger to help you step through the function.

Q1 - testA: {'joe': 10, 'tom': 25, 'barb': 10, 'sue': 20, 'sally': 5}
Q1 - testB: {'joe': 25, 'tom': 10, 'barb': 40, 'sue': 15, 'sally': 10, 'mary': 40, 'jean': 10}
----------------------
Q2 - testA: {'joe': 10, 'barb': 10, 'sue': 20, 'sally': 15, 'john': 30}
Q2 - testB: {'joe': 25, 'barb': 40, 'sue': 15, 'sally': 15, 'mary': 40, 'jean': 10, 'john': 30}
----------------------
Q3 - testA: [10, 10, 15, 20, 30]
Q3 - testB: [10, 15, 15, 25, 30, 40, 40]
----------------------
Q4 - testA: 17.0
Q4 - testB: 25.0
----------------------
Q5 - testA:
barb     10
joe      10
john     30
sally    15
sue      20
Q5 - testB:
barb     40
jean     10
joe      25
john     30
mary     40
sally    15
sue      15
----------------------
Error: name is not in dictionary.
Q6 - testA: -1
Q6 - testB: 40

Grading

You will be graded based on the quality of your code and that the output of each function matches the expected result. I will be checking to see that you correctly computed the solution programmatically.

In order to receive any credit, your program must run without syntax errors in Thonny.

How to submit

Double check that your program runs without syntax errors. Submit the file hw07.py updated with your changes to Moodle.