CS 100

Logo

Scientific Computing

HW 4

Download and save the file hw04.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. Run it to test that it works.

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.

To help you check that your program produces the correct result, here is a sample output from my answer key. Your finished program should output the same once all your code is correctly added:

Q1 - testA: [7, 9, 'a', 'cat', False]
----------------------
Q2 - testA: [7, 'a', 'cat', 'dog', 7, 9, 3.14, 7]
Q2 - testB: ['e', 'c', 'b', 'dog', 'bird', 42, 3.14, 7]
----------------------
Q3 - testA: ['fun', 'with', 'python', 'programming']
Q3 - testB: ['if', 'you', 'like', 'this', 'class', 'you', 'might', 'like', 'CS110', 'too']
----------------------
Q4 - testA: 4
Q4 - testB: 10
----------------------
Q5 - testA: 3
Q5 - testB: 4
----------------------
Q6 - testA: -1
Q6 - testB: 5
----------------------
Q7 - testA: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Q7 - testB: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Q7 - testC: ['I', 'hope', "you're", 'having', 'a', 'really', 'good', 'day']
----------------------
Q8 - testA: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Q8 - testB: ['hi', 'cs', 'students', 'how', 'are', 'you']
----------------------
Q9 - testA: -10
Q9 - testB: 5
----------------------
Q10 - testA: {'joe': 10, 'tom': 25, 'barb': 10, 'sue': 20, 'sally': 5}
Q10 - testB: {'joe': 25, 'tom': 10, 'barb': 40, 'sue': 15, 'sally': 10, 'mary': 40, 'jean': 10}
----------------------
Q11 - testA: {'jean': 15, 'carol': 10, 'laurence': 50, 'deanna': 25, 'charlie': 18, 'reem': 12, 'sally': 30}
Q11 - testB: {'jerry': 5, 'therese': 8, 'carol': 6, 'jean': 15, 'tim': 1, 'sally': 30}
----------------------
Q12 - testA: [5, 10, 10, 12, 18, 25, 50]
Q12 - testB: [1, 3, 5, 6, 8]
----------------------
Q13 - testA: 18.571428571428573
Q13 - testB: 4.6
----------------------
Q14 - testA:
carol           10
charlie         18
deanna          25
jean            5
john            10
laurence        50
reem            12
Q14 - testB:
carol           6
jean            3
jerry           5
therese         8
tim             1

----------------------

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 updated with your changes to Moodle.