CS 151 - Introduction to Computer Science

Fall 2019


Study Guide

Terms

  • Algorithm -

Commands

Python3

  • Data types: integer, string/character, float/double, Boolean

Style Guide

For the 9am section of the class, you should follow these rules in writing your Python code to be using good style. All of these help your code be more readable/understandable and should also reduce the number of mistakes you make. An example file - code/multiply.py

  • Variable names - use meaningful names. You can use i, n, j, k, x, y for integers or numbers if you only havea few of these in your program. The more different variables you are using, the more important that you use a descriptive name.
  • Function names - use good names for functions that describe what they are doing.
  • Variable and function names - use camelCase for variable and function names that consist of multiple words. For example, countLines or countEvenLines.
  • Function comments - right before a function include a brief description of what it does, what the parameters are supposed to mean, if there is a return value what it means, and anything else someone would need to know to be able to call your function properly.
  • Using functions - break your code into smallish separate tasks that can each be solved with a function. You should not have more than about 20 lines of code in each function, and your main program that uses the functions should not be more than about 20 lines of code.
  • Empty lines - one before any loop, two before any function definition.
  • Line length - make your code so it still looks good in the default putty/terminal size (which is normally 80 characters widw).
  • Top of the file - at the top of your file include - basic purpose of the file / what it does, the name of the authors, a change-log, if you took anything as a starting point (e.g., code from class or something you found online), if you received assistance from anyone (instructor, unix lab, friend, aunt, etc.), and anything someone would need to keep in mind to run your program properly.
Note: course website layout/code/template from Steve Baker. Anything horrible is not his fault.