Programming fundamentals

<< Previous: Algorithms testNext: Programming constructs >>

Variables and constants

Variables are named storage locations, used to store data that might change during the execution of a program e.g. score = 0. Variables should have meaningful names and must start with either an underscore or a letter and cannot contain spaces.

Constants are a storage location for data that doesn’t change during the running of the program e.g. VAT = 0.2. It's common to use all capital letters for the names of constants. This stops progammers accidentally changing their value.



Operators

An operator performs an action on one or more operand/s. Arithmetic operators are used in mathematical operations and comparison operators are used to make Boolean conditiions i.e. ones that evaluate as true or false e.g. 2*5==10 would evaluate as true

Boolean operators can be used make more complex comparisons. The Boolean conditions you need to be familiar with are AND, OR and NOT.



Assignment

Assignment means giving a variable a new value. Assignment in both OCR reference language and Python uses a single equals sign e.g. name = "Bob". Assignment always happens left to right.

Input and output

Inputs means data entered into the program by the user. This data needs to be stored somewhere so we need to use assignment to assign the response to a variable. One of the most common mistakes programmers make is to request input, which stops the program and gets the user to enter data, but then forget to store it. The standard input statement gets string input so it should be cast if you want integer or float input.

Outputs refers to outputting information to the user. OCR reference language and Python both use the print command for this. In OCR reference language concatenation joins strings and variables with a plus sign, however there are several was to do this in Python.


Knowledge check


Questions:
Correct:

Question text


<< Previous: Algorithms testNext: Programming constructs >>

© All materials created by and copyright S.Goff