CSC 111: Intro to Computer Science through Programming

Homework 1

Due: Tuesday, Feb. 7 at 11:59pm on Moodle

The goal of this homework is to practice several concepts we have been learning so far: user input, strings, built-in functions, numerical computations in Python, and for loops. For this assignment, you are welcome to discuss your work with other students, but all code you submit should be your own original work. It should be produced and understood by you, without looking at anyone else's assignment. I want to encourage you to start early on this homework, but it will also be helpful to have completed Lab 1 on Wed/Thurs.

Credit: based on materials from Joe O'Rourke and Dominique Thiebaut.

Set up Python

  1. If you have not done so already, download and install the latest version of Python (or any version of Python 3) from the official Python website.

  2. To find IDLE, go to "All Programs" in Windows and "Applications" in Mac. Then find Python 3.x and from there, open IDLE. This will open the Python interpreter or the shell, where you can experiment and test your code.

  3. Go to "File" and "New File" to open the editor where you will write your code.

    IDLE

Part A: Computing Taxes

Create a new file and save it as hw1A.py. Make sure to include the assignment name and your name as comments on the top of your program. In this program we will ask the user for several pieces of information, then compute their taxes.

For federal taxes, use the formula: (salary - deductions) x 28%

For state taxes, use the formula: (salary - deductions) x 5%

(These are approximate for some tax brackets.) Add the federal and state taxes together to obtain the total amount of tax the user has to pay. An example of this program running is shown below:

taxes

Try to make the output match exactly, then try out a few different names, salaries, and deductions (you will submit these tests are part of your transcript).

Part B: Distance Conversions

Now create a new file and save it as hw1B.py (again including the assignment name and your name at the top). In this program you will ask the user for their speed in miles per hour. Then you will convert several distances in kilometers to miles, using a for loop. After that, using the distance in miles and the speed in miles/hour, compute the time it will take (in hours) to cover this distance. An example is shown below:

distance

Again try to match this output exactly. In your program, make sure to think about variable names, comments, and automation. Your program should use a for loop, not print out each computation individually. You will be evaluated not only on correctness, but readability and Python style.

Transcript and Submit

Finally, create a transcript that demonstrates your code working. From the shell, highlight all the testing you have done and all the output and copy it into a plain text file (.txt extension). On Windows you can use the program Notepad (under Accessories) and on Mac you can use the program TextEdit (under Applications). Save this file as hw1_transcript.txt.

TO SUBMIT ON MOODLE:

  • hw1A.py

  • hw1B.py

  • hw1_transcript.txt