Assignment 1 - Problem Statements
You are getting the first edition of all these pages. Please let me know if you find an error!
“Programming all too often begins without a clear understanding of the problem.”
– J.M. Yohe1
A good problem statement contains2:
- Concise and precise statement of the problem
- Clearly specified input format. What does the data look like?
- Input could come as function arguments, file contents, or user console input.
- The “format” is what this data looks like, e.g., three integer values separated by spaces on a line.
- Clearly specified output format
- Output could be printed to the screen, text written to a file, or the values returned from a function.
- As with input, what does this data look like?
- Indication of any exceptional conditions, e.g., things you should check for (like invalid values) and what you should do if they occur.
- Sample input
- Sample output
Part A - write a problem statement
This will be completed in class.
With a partner (required): Write a problem statement using the best practices described in class. Here is the high-level problem:
Write a program where the user enters three side lengths and the program says if they can form a triangle or not. This is the Triangle Inequality Theorem.
Suppose we label the numbers
a
,b
, andc
. They can form a triangle if:a + b ≥ c
, andb + c ≥ a
, anda + c ≥ b
.
The program can accept a single set of input values, produce a result, and then terminate. Or, you can include a loop that allows the user to repeat the process multiple times before quitting. It’s up to you.
Use this plain text template to write your problem statement. You must save it as a plain .txt
file, not Word or anything else.
Grading
You and your partner have complete freedom in specifying your problem so long as the following criteria are met:
- It accepts user input and produces output for the user.
- It correctly calculates the result.
- The statement identifies at least two exceptional conditions and how they will be handled.
Rubric
- (6 pts) All elements of the template are completed.
- (1 pts) At least two exceptional conditions are specified.
- (3 pts) Correct spelling and grammar.
Submission due Sep 3
Each partner submits their team’s spec.txt
to the Canvas assignment page.
Part B - Implementation
Individually create triangle.py
and implement the problem you specified in spec.txt
.
The goal is to warm-up your Python skills, and to see how the implementations of two people working from the same spec will be different.
You may not share code under any circumstances. Getting answers to simple Python questions from your peers is fine. Review the Syllabus section on Collaboration and Cheating for what is allowed and not allowed. If in doubt, ask me – I promise I won’t be mad if you ask.
Grading
You are graded on the correctness of your code, not the correctness of the spec.txt
. If you discover an error in your spec.txt
, you may communicate it with your partner.
Rubric
- (10 pts): Functionally correct implementation that (a) accepts user input according to the format in your spec, and (b) produces correct output as to whether the input can form a triangle or not for several valid input values.
- (5 pts): The program detects and handles at least two exceptional conditions you specified in
spec.txt
. “Handling” means it does not crash with an exception, but terminates or continues gracefully.
You will receive 0 points if your program does not run due to syntax errors or does not complete under “normal” conditions.
Submission due Sep 5
Submit the following to the Canvas assignment page:
- your
triange.py
file - your
spec.txt
file (again) including any changes