Computer Science 217
Assignment #1
To become familiar with Unix and Python, and write a small Python
program.
- This is an individual assignment. What you submit must be your own
work, although you may discuss the problem in general terms
with other students. You should definitely not be showing other students
your code, and generally speaking, it is not a good idea to talk about
the assignment when you're sitting in front of the computer.
- Sources of algorithms and code, if any, must be properly cited.
Remember that plagiarism regulations apply to code too.
- If you have any questions about what you can and can't safely do,
read the information on the
what to avoid page.
If you still have questions, feel free to email me.
Write a Python program that does four things:
- Prompts the user to enter a base 10 number.
- Reads a base 10 number from the user.
- Converts the base 10 number into base 2 and prints it.
- Converts the base 10 number into base 8 and prints it.
You may assume that the number will be positive and will never be larger
than 255.
Some sample runs of a solution would look similar to this:
% python as1.py
Enter a base 10 number: 42
42 in base 10 is 0 0 1 0 1 0 1 0 in base 2
42 in base 10 is 0 5 2 in base 8
% python as1.py
Enter a base 10 number: 255
255 in base 10 is 1 1 1 1 1 1 1 1 in base 2
255 in base 10 is 3 7 7 in base 8
% python as1.py
Enter a base 10 number: 0
0 in base 10 is 0 0 0 0 0 0 0 0 in base 2
0 in base 10 is 0 0 0 in base 8
If you know how to use loops, you may use them, but there are no
bonus points for doing this.
- To read input, you can use Python's
input
command, or a
combination of raw_input
and int
. You may not
have been taught about these in class early on, and this is deliberate;
it's important to learn techniques for finding out information
yourself.
For example, a web search
for the words python raw_input
may be useful.
- If you put a comma after a
print
statement, then Python
doesn't print a new line. For example, try the two programs
print 123
print 456
and
print 123,
print 456
and compare their output.
- In your program, use lots of variables for intermediate computations,
and give them names meaningful enough that
you can figure out what's going on. Document how you name
your variables so the TA will be able to figure it out too.
- Base 8 conversion will be easier, i.e., shorter, than base 2
conversion; you may want to start there.
- Test your program to make sure it works properly, using examples
from class as well as ones you work out yourself by hand.
- Make a directory to keep your files for this assignment in.
- Take notes as you go along, so you can remember what you've
tried already and what did and didn't work.
- Break the task down into small pieces.
- Use an incremental approach, and try out things as you go.
- Work through everything one last time prior to your demo to
help catch any last-minute problems.
You must do two things:
- Hand in a printout of your solution to the assignment boxes by
4pm Monday, February 1, 2010. Make sure it has your name
and/or student ID number on it, and double-check to ensure
you're using the correct assignment box! The assignment boxes are
on the second floor of the Math Science building.
If your TA is accepting solutions in any other form (e.g., email)
then they will let you know - however, you must still observe
the deadline.
- Demonstrate your solution to your TA in tutorials during the
week of February 1. To keep things fair,
the solution you demonstrate must
be the same as what you handed in on the printout, or you will
not be given credit for the demo. Your TA may ask you
questions about what the different parts of your
solution do, and may also ask you to perform basic
Unix commands.
If you do not hand in a printout or if you do not demonstrate your
assignment during tutorial time, or both, you cannot be given a grade
above a zero on this assignment.
Your printout must show your Python program.
Note that you must have a program in a
.py file - you cannot turn in a solution that only
uses the Python command line.
Your solution must be demonstrated using your account on the CPSC machines.
Tutorials during the week of February 1 are allocated for demos. Your
TA is not obliged to see demos outside this time; they have their own
schoolwork to do!
The TA has the right to assign a mark of zero for the entire assignment
if you fail the demo.
Half of
the marks are for functionality (i.e., the demo) and
half are for your solution (as shown on the printout). Note that,
in keeping with the University's assessment criteria, simply having
a working solution does not automatically mean that you get
full marks. For example, better solutions will have more readable code.
Michael Jacobson, Jr.
2010-01-19