CSC323 2010S Software Design

Assignment 2: Python Basics

Assigned: Tuesday, February 2, 2010
Due: 1:15 p.m., Thursday, February 4, 2010

This assignment is also available in PDF.

Summary: In this assignment, you will further explore the Python programming language.

Purposes: To encourage you to explore a bit more Python.

Expected Time: Two to three hours.

Collaboration: You may work in groups of up to size four. You may also work individually. You may talk to whoever you wish about this assignment, provided you cite appropriately. I would prefer that you not search for answers on the Internet.

Submitting: Email me your answers. Use a title of CSC 323: Assignment 2.

Warning: So that this assignment is a learning experience for everyone, I am likely to spend class time publicly critiquing your work.


A. Implement binary search in Python. You should write a procedure, binary_search(i,vals), that takes as input an integer and a list of integers, sorted in increasing order. Your procedure should return an index of i, assuming i appears in vals. If i does not appear in vals, your procedure should return -1.

B. Create a simple Fraction (Rational number) class in Python. Your goal in creating this class should be to make sure that you understand the various methods you can define and override. Your code should provide reasonable answers to expressions like the following:

>>> x = Rational(1,3) + Rational(1,2)
>>> print(x)
>>> Rational(1,3) < Rational(1,2)

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue Feb 2 15:57:47 2010.
The source to the document was last modified on Tue Feb 2 15:57:46 2010.
This document may be found at

You may wish to validate this document's HTML ; Valid CSS! ; Creative Commons License

Samuel A. Rebelsky,

Copyright © 2010 Samuel A. Rebelsky. This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.