HW 1
HW 1
HW 1
Homework 1: Input/Output
Introduction
The most basic function of any piece of software is to transform input into output. When thinking about
the requirements of a program, software developers often speak of the ”Input/Output (I/O) Specification”:
What form of input will the program receive, and what is the target output that the program must
produce. A program is written or implemented to meet these I/O requirements. It’s up to you, as the
coder, to figure out how to perform this transformation. For example, with electronic medical records,
a doctor might enter a patient’s age and weight and the name of a medication into a computer. A
program then computes the correct dosage - the output. In this first homework you’ll write several small
programs that transform input into output. We’ll specify the required user-inputs and you will write
a small program to generate the expected outputs. You’ll use some built in python functions in your
implementation including input, print, and round along with arithmetic operators (+, -, *, /, //, %,
**).
Expectations
Write a separate program (program.py) to answer each question. Be sure to document your code with
a descriptive header and concise comments. It isn’t necessary to comment every line, particularly those
lines whose purpose is obvious. Instead, use comments to outline the main steps of your program. Use
variable names that are descriptive, concise, and not excessively verbose. Practice good style: x = 5, not
x=5 and separate sections of your program by blank lines. For your homework submission, submit these
files:
• output.pdf or output.txt: The output for each of your programs combined into a single file.
This can be either a simple text file, or you can paste screenshots into a word document and save
the resulting file to a .PDF. (Do not submit a .DOC or .DOCX file. Please convert the document to
a PDF-formatted file so that the graders can see your output in gradescope without
with having to download
your output file.)
You are welcome to upload a file multiple times, but only your last submission will be graded. Verify
that all files have been submitted.
DS2000, Fall 2022, Profs. Muzny and Rachlin – Homework 1: Input/Output 2
Question 1 (running.py)
Write a program where a runner inputs their running distance (kilometers - float) and time (minutes
and seconds - integers). The program should output the average pace measured in minutes per mile.
There are 1.61 kilometers per mile. Note that the program should accept the distance as a floating point
(decimal) number, where as the total running time is entered as two integers (minutes and seconds).
Question 2 (mortgage.py)
Suppose you are buying a house. Write a program to calculate your monthly mortage payment. The
inputs are:
Question 3 (light.py)
Light travels at 299,792,458 meters per second. Input an astronomical object’s distance in miles - an
integer. Report the number of hours, minutes, and seconds it takes for light from that object to reach the
Earth. Seconds should be rounded to one decimal place. The examples below are for the approximate
distances to the Moon, the Sun, and Pluto in miles. Assume that 1.61 kilometers = 1 mile and 1000
meters = 1 kilometer.