Computer Sciences Department logo

CS 368-2 (2012 Spring) — Day 1 Homework

Due Thursday, March 15, at the start of class.


Find a working Python system and become a bit more comfortable using it.

If you are not comfortable using the command line or editing text files (for code, i.e., not with Word), please see my page with tips for beginners.


Part I

Essentially, this part of the homework is to make sure that you have a working Python environment to use for the first half of the class. Complete these steps:

  1. Find/pick a machine to work on
  2. Set up a working directory on that machine
  3. Save the following Python code in a file named ""
    #!/usr/bin/env python
    """Homework for CS 368-2 (2012 Spring)
    Assigned on Day 01, 2012-03-13
    Executed and printed by <Your Name>
    import getpass
    import os
    import platform
    import socket
    import sys
    import time
    print __doc__
    print 'Time    =', time.strftime('%Y-%m-%d (%a) %H:%M:%S %Z')
    print 'Host    =', getpass.getuser(), '@', socket.gethostname()
    uname = platform.uname()
    print "System  =", uname[0], uname[2], uname[4]
    print "Version =", platform.python_version()
    print "Program =", sys.executable
    print 'Script  =', os.path.abspath(__file__)
  4. Run the script like this:
  5. If it fails, ask someone you know or the instructor for help
  6. Once it works, read below for what to hand in

Part II

Play around!

Start interactive Python. Use numbers, strings, and operations to make expressions. Experiment. Maybe read about operations that were not covered in class and try them out. Can you calculate interesting things? Can you mix numbers and strings to make formatted output? Can you put together expressions that are relevant to your research or class work?

Pick the five most interesting expressions (and their resulting values). Expressions like 1 + 1 are not interesting. Copy your interesting expressions into your homework. If you need to explain things, just add notes.

Examples (do not use yourself!):

Convert 42.0 degrees Fahrenheit to Celsius
>>> (42.0 - 32.0) * 5.0 / 9.0

Area of circle with radius = 2.5 units
>>> 3.14159 * (2.5 ** 2)

Formatted version of above
>>> 'Area = %.1f' % (3.14159 * (2.5 ** 2))
'Area = 19.6'

Hand In

A printout of your output on a single sheet of paper. For Part I, just include the output; for Part II, include the five expressions, the Python output from them, and any blank lines and comments to make things clear. In Part I, be sure to replace “<Your Name>” with your own name before running the script. Identifying your work is important, or you may not receive appropriate credit.

Other Rules

Normally, you will do each homework by yourself. But in this case, you may ask for help from anyone who knows how to get Python running on your machine. Be sure to use a machine that you can use for the rest of the class, because you really want to make sure Python is working right…