CS 100

Logo

Scientific Computing

HW 6

Download and save the file hw06.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. There are 10 questions total, each worth 1 point. The questions are written in comments. Each question involves you implementing a function below it to solve a specific problem.

Note that questions 5-10 involve you implementing a python function that works like one of the list methods already provided by Python. Although Python provides this functionality, it is good practice and instructive to consider how it is implemented. DO NOT simply call the equivalent function – write your own implementation. This includes functions for

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: [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: False
Q8 - testB: True
----------------------
Q9 - testA: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Q9 - testB: ['hi', 'cs', 'students', 'how', 'are', 'you']
----------------------
Q10 - testA: -10
Q10 - testB: 5

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