CSC108H/A08H Assignment 1, Summer 2011

Due: Friday 3 June, by 11:59 pm sharp!

Contents

The purpose of this assignment is to give you practice writing your own Python code that uses variables, assignments, if-statements and functions, as well as practice writing docstrings.


Introduction

This is a quick and easy assignment, intended to ensure that you become comfortable with basic programming. It should not be any trouble if you've been following the lecture and labs. The ease of this assignment should not be considered to be indicative of following assignments.

This assignment will cover the basics of booleans, and functions. You will be expected to write good docstrings for each function that you write. It is intended to get you comfortable writing basic functions, and to get you to be able to jump from abstract thought to programming and back. I want to emphasise that this is very much a getting feet wet exercise, as opposed to a swimming one.


Partners

This assignment is to be done individually.


Your Task

Download the file assignment1.py, and write the functions listed in the table below. Include a docstring comment for each function. The docstring should be an appropriate rephrasing of the specification on the right-hand side of the table. See the A1 Assignment rules page for guidance on how to write good docstrings.

In the table below, we provide the parameter types for each function. When you write your function definitions, you will replace these types with your own names for the parameters. Make sure you pick good names. Again, look at the A1 Assignment rules for help with this.

Some of the functions are useful "helpers" for other functions. That is, they can be called by another function to do part of its work. Take advantage of this to avoid repetitive code. You are permitted to write additional helper functions as well.

Function Name Description
xor(bool,bool) Given two bool variables, return the xor of them. Recall from lecture that the xor (or exclusive or) of two boolean variables is what we would expect from the English definition of or. That is, it is True iff one of the input values is True.
implies(bool,bool) Given two bool variables, return False if the first input value is True, and the second is False. Otherwise return true. This connective has the meaning 'If the first variable is true, then the second is true'. Note that because it evaluates to a boolean expression itself, the way in which it is implementend is somewhat distinct from informal meaning of the connective.
find_factor(int) Given an int variable, return a factor of that int. If the input is not between 0 and 100 return -1. If there are more than one distinct factors, return the second smallest. 1 does not count as a factor.
distance(int,int,int,int) Given two points represented as x1,y1,x2,y2 return the (float) distance between them. You may find the math.sqrt function useful.
get_slope(int,int,int,int) Given two points represented as x1,y1,x2,y2 return the (float) slope of the line between them.
get_intercept(int,int,int,int) Given two points represented as x1,y1,x2,y2 return the (float) y-intercept of the line between them.
get_y_value(int,int,int,int,int) Given two points and an x co-ordinate represented as x1,y1,x2,y2,x3, return the (float) y co-ordinate of the line represented by the two points at the third x co-ordinate given. That is, the line represented by the two points will have some y value at the x co-ordinate given. Return that value.
get_x_value(int,int,int,int,int) Given two points and an y co-ordinate represented as x1,y1,x2,y2,y3, return the (float) x co-ordinate of the line represented by the two points at the third y co-ordinate given. That is, the line represented by the two points will have some x value at the y co-ordinate given. Return that value.

Additional requirements

  1. Your functions must be put into one module called assignment1.py
  2. Your module must consist of the following, in order:
  3. Your functions must have absolutely no user-input (i.e. nothing that the user types). Also, your functions must have absolutely no output -- no print statements; no messages to the user (not even a "welcome!"); and no displaying of pictures, or else it will be marked as incorrect.
  4. If your code does not compile, it will be marked as incorrect.
  5. Your module must not contain any other code.
  6. You should not to do any error checking for this assignment. Assume that all input values to the functions you design are within the bounds outlined by the assignment description. Specifically, you don't need to worry about what happens if you get two identical points.


Testing and Marking

Testing your code

This assignment is simple enough that you are wholly responsible for testing you code.

Marking

These are the aspects of your work that we will focus on in the marking:


Submitting your assignment

You must hand in your work electronically, using the MarkUs online system. Instructions for doing so will be posted on the Assignments page of the course website.

For this assignment, hand in just one file:

Once you have submitted, be sure to check that you have submitted the correct version; new or missing files will not be accepted after the due date. Remember that spelling of filenames, including case, counts. If your file is not named exactly as above, your code will receive zero for correctness.


Hints and Tips