Logic and Formatting
Basic computer programming logic and Python specific formatting is used throughout this course. Since no prior programming knowledge is a requirement for the course, only needed topics in formatting and logic will be discussed.
- Variables:
- are words or letters that should provide a description of the contained information. A variable can be in either numerical or text format.
- can contain a single piece of data such as a person’s last name or multiple data items (a list or an array) such as the names of every student enrolled at a college.
- a solid naming convention for the variables should be used in scripts and from one script to another. By using a solid naming scheme, it will be possible to identify the purpose of the variables.
- predefined names that cannot be used as a variable name (reserved words that are defined for specific operations).
- should also avoid the use of blank spaces.
- Additional modules/libraries can be loaded into Python, this keeps the script smaller, thus loading only what is required makes the code very flexible and easy to move from one computer to another as long as the new computer contains the library or has a path to the library. It also provides uniformity in how the script is composed.
- In general, the first letter of all program lines should be lower case, some editors want to capitalize the first letter.
- Anything contained within double quotation marks (“”) or single quotation marks (‘ ‘) is considered text (string).
- A pound sign (#) is used for comments, it is a requirement for this course that you use comments throughout the program to explain what is being created. In addition, when trying to troubleshoot errors in a script use a # sign in front of an operational line, this will change the line to a non-operational line without the need for deleting the code. Comments can be placed at the end of an operational line, to describe that specific line. However, in most cases comments should be placed on their own line. Comments can also be used to separate parts of a script. At the beginning of every script comments should be used to identify the author, organization and contact information as well as the purpose of the script.