HW 3

Download and save the file hw03.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. You should see the following as a result in the shell area:

Question 1 - test:  0
------------------------------
------------------------------
------------------------------
------------------------------
------------------------------
------------------------------
------------------------------
------------------------------
------------------------------

There are 10 questions total - each worth 1 point. Each question involves you writing a function to solve a specific problem. The questions are written in comments.

For example,

## Q1. Finish/fix the following function so that it returns
## the sum of the first 100 even numbers (beginning with 2)
def q1_sum():
    # your code here
    return 0

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. The first one is uncommented for you.

To help you check that your program is 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:

Question 1 - test:  10100
------------------------------
Question 2 - test:  2500
------------------------------
Question 3 - test:  100.0
------------------------------
Question 4 - testA:  50.5
Question 4 - testB:  100.5
------------------------------
Question 5 - testA:  120
Question 5 - testB:  3628800
------------------------------
Question 6 - testA:  False
Question 6 - testB:  True
------------------------------
Question 7 - testA:  True
Question 7 - testB:  True
Question 7 - testC:  False
------------------------------
Question 8 - testA:  True
Question 8 - testB:  False
Question 8 - testC:  False
------------------------------
Question 9 - testA:  True
Question 9 - testB:  False
------------------------------
Question 10 - testA:  False
Question 10 - testB:  True

Grading

You will be graded based on the quality of your code and that the output of each function matches the expected result. For example, you will not get any credit if you simply return 10100 for the first question. I’m providing the sample output to help you check your work, not to cheat :) I will be checking to see that you correctly computed the solution programmatically - such as using an accumulator, for loop, range statement, etc.

In order to receive any credit, your program must run without syntax errors in Thonny. Thonny reports syntax errors in red in the shell area; if Thonny outputs an error, your code isn’t usable. Code that doesn’t run is just text - it’s not a program. It’s an important part of programming and problem solving to come up with a solution that can be shared with others.

Your program doesn’t have to be perfect to be eligible for credit! It’s okay to have some semantic errors. Semantic errors don’t stop your program from running, but they cause your program to produce an unexpected or incorrect result. For example, if your program is supposed to calculate the sum of the first 100 numbers, but instead it accidentally calculates the sum of the first 101 numbers, that would be a semantic error. Semantic errors may result in partial credit depending on how close your solution is.

How to submit

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