- A partial summary our digital problem solving and pythonics to date.
- An algorithm is writeable, unambiguous, completeable, and deterministic list of instructions, where
- Writeable means the description of the algortithm has finite length
- Unambiguous means the instructions are completely understandable
- Completeable means carrying out the instructions takes finite time
- Deterministic means whenever given the same inputs, the algorithms produces the same results.
- A program is an algorithm expressed in a programming language.
- In programming parlance, instructions are called statements.
- Synonyms for carrying out the instructions of a program are executing or running.
- Programming languages provide grammars (rules of structured communication) for producing syntactically correct (legal) code.
- Programming languages detail the specific actions to be taken (semantics) for each of its grammar rules.
- Style rules are (optional and legal) ways of writing code to support program reaability; e.g., snake_case.
- A program comment is an aside (explanation) to the reader. A comment is not program statement — there is no action associated with a comment other than to ignore it.
- A header comment identifies program user, purpose, and clarifications
- Whitespace is using horizontal or vertical spacing to separate different code elements; e.g., blank, tab, and indentation. Whitespace does not affect program interpretation.
Translation and execution
- A compiler translates valid (i.e., syntactically correct) progamming language code (list of statements) from one language (source code) into another language (target code).
- An interpreter is a kind of compiler that carries out (executes) the statements as they are translated,
- A scripting language supports the automation of tasks in (special) run-time environments.
- A Python single-line comment begins with a
# and continues for the rest of the line.
- A Python multi-line comment begins with a
''' and continues until another
''' is found.
- A Python program is a list of statements written in Python executed one-at-a-time from top-to-bottom.
- A Python interpreter verifies that the entire code file is syntactically correct before execution begins.
Programming language elements
- A literal is an explicit fundamental type value; e.g.,
- An identifier is a symbolic name for a value or predefined action. A variable names mut be an identifier; i.e., a letter followed by zero or more letters and numbers).
- In an identifer, lettercase matters; e.g.,
Email_ID are different identifiers. Most seriously suggest do not have two identifiers whose only difference is lettercase.
- A program action is written as an expression. An expression is evaluated to determine the value it represents. Expressions are ubiquitous in Python.
- An assignment statement firsts evaluates the expression to the left of the assignment operator
= and assigns the variable to the right of the
= that value.
- The arithmetic operators are
** and perform respectively addition, subtraction, multiplication, decimal division, integer division, remainder (modulus), and exponentiation.
- The relational operators are
** and perform respectively less than, less than or equal to, greater than, greater than or equal to, equality, and inequality comparisons.
- The logical operators are
not and perform respectively logical and, logical or, and logical negation
- Besides assignment, there are several other kinds of progam statements. They include
import statements that add Python external code (module) that can be used by a program
- Stand-alone function invocations; e.g., print( 'continental' )
for statement that supports looping over a sequence of values.
- A function is a named block of code.
print() function produces output to the program user.
print() function is one of many built-in (predefined) functions to support frequent programming tasks.
- A function invocation causes its block of code to be executed.
- A function invocation consists of the function name, parentheses, and within the parentheses a list of zero or more comma-separated values (arguments); e.g,.
print( 'ai' )).
- Typical steps to solve a problem
- Mindfully read the problem specification
- Seek clarity for ambiguity or possible mis-specification
- Determine the required values for solving the problem
- Develop an algorithm for the problem
- Implement the algorithm as a program
- Verify program faithfully solves the problem (e.g., testing)
- Repeat above steps as necessary
- An interactive program gets input and produces output. It provides a solution for a collection of problem instances.
- A non-interactive program solves a single problem instance.
- Typical interactive program steps
- Import libraries to assist with problem solving
- Define constants that characterize the problem
- Convert input into problem instance to be solved
- Compute solution — i.e, problem solve