You can test most of the items in the "Formatting" section by copying your program to the cwolf server, logging into cwolf and navigating to the correct directory, and running the following command. Fill in the name of your file where indicated:
~srivoire/bin/python_style_check.sh yourprogram
Pay attention to any output this program prints. If it doesn't produce any output, then you're in good shape.
The error codes refer to the Python PEP 8 style guide, which is the basis of these rules.
Here is how to read an error message from this command:
proj1.py:10:1: W293 blank line contains whitespace ^
The "10:1" means that the error occurred on line 10, column 1 of your source code file. You can reopen emacs directly to this line by using a "+10" (since you want line 10):
emacs +10 proj1.py
The "W293" refers to the PEP8 rule that your code violates. In this example, a "blank" line in the source code actually has invisible tabs or spaces.
Finally, the error message will show the offending line of your code, and put a
^symbol underneath the specific error. Since this source code had extra space in a "blank" line, it printed a blank line and marked the beginning of that line.
There should be a docstring at the top of your submitted file with the following information:
1 pt. | Your name (first and last) |
1 pt. | The course and assignment (e.g. CS 115 Project 1) |
2 pts. | A brief description of what the program does |
Not counting the docstring, your program should contain at least three comments explaining aspects of your code that are potentially tricky for a person reading it to understand. You should assume that the person understands what Python syntax means but may not understand why you are doing what you are doing.
6 pts. | You have at least 3 useful comments (2 points each) |
4 pts. | Variables have helpful names that indicate what kind of information they contain. |
The most common ways to lose points are:
3 pts. | Your algorithm is reasonably efficient, with no wasted computation or unused variables. |
These guidelines come from the Python PEP 8 style guide.
Pay attention to any squiggly underlines you see in Pycharm! They often indicate violations of PEP8. You can hover the mouse over each squiggle to see an explanation of the problem.
3 pts. | Operators and spacing:
|
1 pt. | Indentation and whitespace:
|
2 pts. | Blank lines:
|
2 pts. | Comments:
|
2 pts. | Line length: Your lines all have fewer than 80 characters. You can have statements that are longer, but you must break them across multiple lines to increase readability. Ask the instructors if you need help breaking up long lines. |
All or nothing: your code should define a main function and then call that function, just like our programs do in class and lab. Other than library imports, the docstring, and the final call to main(), you should not have any stray code outside a function definition.
How to check for this: look along the left margin of your source code. You should only see your initial docstring, import statements, def statements, and the final call to main(). Anything else, and you lose these three points.
For students using language features that were not covered in class, up to 5 points may be taken off if the principles of programming style are not adhered to when using these features. If you have any questions about what this means, ASK!