Submission Requirements

All lab, and project submissions are graded on several factors, including basic requirements concerning the procedures and style of your submission. You can’t hand in an assignment any way you want, formalization and standardization make for easier grading and understanding of your code.

The following are general procedures.

Documentation String (“docstring”)

Read up on Python Docstrings on the Program Documentation String page. Docstrings consist of three quotes ("""), a summary line, followed by a blank line, followed by a more elaborate description, and ending with three quotes.

A specifically formatted docstring will be required to be the very first thing in your submitted Python program files.

The line format of the standard docstring I want is as follows:

  1. Docstring triple-quote, and the title “CSC 161 <assignment type>: <assignment name>” * Where “assignment type” may be “Lab”, “Quiz”, “Project”. * Where “assignment name” is listed clearly on the assignment page.

  2. Empty line

  3. Your name as seen on Blackboard/Gradescope

  4. The lab or lecture (summer courses only) time and date

  5. The semester title and year

For example:

"""CSC 161 Lab: Computer Programs

Fox Mulder
Lab Section TR 2:00-3:15pm
Fall 2015
"""

Python Code Style

  • Code Style. Make use of the online PEP 8 style checker to see if your Python code conforms to good Python coding style.

    Note: As Emerson wrote: A Foolish Consistency is the Hobgoblin of Little Minds. In our case, understanding when to be inconsistent is more important than being perfectly consistent.

    For example: It maybe more more work to reduce slightly long lines than necessary, which may also affect the readability of your code!

    Maintain good style, but also think for yourself and make good decisions while doing it!

  • A main() function. I require a main() function for almost everything I have you write. While you may not know how the if conditions work, I will still require the below template. It will be properly explained when we reach the Decision Control topic.

    def main():
        print("Hello World!")
    
    if __name__ == '__main__':
        main()
    
  • Line Length. Your source code should not contain lines that are longer than 79 characters long. If you have a line that is longer than 79 characters, break it up into multiple lines.

    There are two basic techniques for this:

    1. Use the '\' (backslash) character.

      Add a backslash “" to the end of a line to tell the Python interpreter that the statement continues on the next line. Here is an example of how to break up a long boolean expression into three lines:

      if (blah < 0 ) and (grr > 234)) \
              or (foo == 3456) and (grr <= 4444) \
              or(blah > 10) and (grr == 3333):
          print("this crazy condition is true")
          print("and my code is really easy to read because")
          print("I didn't wrap lines!")
      
    2. Use bracketing characters, e.g. '{}, (), []'.

      Certain constructs, like if statements, literal lists or dictionaries, can be easily broken into multiple lines because their contents are bracketed. For example, here’s how to break a long if statement. There is a pair of parentheses bracketing the entire boolean expression.

      if ((blah < 0 ) and (grr > 234))
              or (foo == 3456) and (grr <= 4444)
              or(blah > 10) and (grr == 3333)):
          print("this crazy condition is true")
          print("and my code is really easy to read because")
          print("I didn't wrap lines!")..
      

Commenting

Comments only readable by humans, and completely ignored by Python when running. They are different from docstrings (which are used for documenting a program).

Comment things are are not obvious in your code, or something you’d like to explain more thoroughly to the grader.

Unclear parts of your code can receive point deductions, as well as using too many comments. Be judicious about comments in your code (comments should match the indentation level of the code of which you are commenting.

# This block comment explains that this
# part of my code does something interesting.
# Block comments should not be overused!
x = 1 + 1

Or, you can use inline comments (two spaces before the # character):

x = x + 1   # Increment x

Read up on comments on the Program Comments page.

Script/Module Check

This won’t be a required until we reach the Decision Control lab. At that time, you must include the __main__, top-level script environment” check:

if __name__ == '__main__':
    main()

Blackboard

Refer to the Blackboard assignment item for any particular lab to read the details regarding the due date, or class administration for this assignment.