Please enable JavaScript.
Coggle requires JavaScript to display documents.
2.2 Programming Fundamentals - Coggle Diagram
2.2 Programming Fundamentals
Variables
A location in memory that stores a value that can change
e.g. name=input("Enter a name")
Constants
A location in memory that stores a value that does not change
PI=3.14 notice the use of capital letters
Comparison Operators
Not Equal to
!=
Equal too
==
Greater than
Less than
<
Greater than and equal to
=
Less than and equal to
<=
Assignment Operator
=
Mathematical Operators
Addition
+
Subtraction
-
Multiplication
*
Division
/
Modulo
% or MOD
Quotient
// or DIV
Exponentiation
** or ^
Boolean Operators
AND
Both inputs must be TRUE
OR
Either OR input must be TRUE
NOT
The input is reversed
Programming Constructs
Sequence
The order of commands
Selection
A choice of routes through a program
IF, ELIF, ELSE
Match Case
Iteration
Counter Controlled
FOR
Condition Controlled
WHILE
Data Types
Integer
A whole number e.g. 1 or 0 or -1
Real
A number with a decimal value e.g. 1.1, 0.0 or -0.1
Boolean
True or False
Character
A single character e.g. !
String
A series of characters e.g. name or phone number
Casting
Changing the data type most common between STR and INT to allow mathematical processes
Additional Programming techniques
String Manipulation
length
.length
substrings
.substring(x,i)
.left(i)
.right(i)
Concatenation
Joining string values together
.upper
makes all characters uppercase
.lower
Makes all characters lower case
ASCII conversion
ASC() or CHR()
Basic File Handling
Open
open ("filename.txt")
Read
.readline()
Write
.writeline("Add anew line")
Close
filename.close()
Records
Storing data that relates the same topic in one place, usually a column in a spreadsheet/databases
SQL
SELECT FROM and WHERE
FROM is always the table name
WHERE is always a comparison
Arrays and Lists
Lists
listname=[]
Arrays
listname=[8,8]
Sub Program
def routine name():
Subroutine call
routine name ()
Parameter passing
variables can be passed from the main program to the subroutine in the brackets e.g def subroutine(var1,var2)
subroutine(var1,var2)
Random Number generation
import random
random.randint(1,10)