programming fundamentals Flashcards
sequence
structuring code into a logical, sequential order
selection
decision making using if statements
iteration
repeating code using for or while loops
what do the three constructs of programming do
control the flow of a program
variable
- a location in the memory that is used to store data in programs
- they can be changed as the program runs
what are the two parts of the variable
data value and identifier
local variables
variables that are declared within a specific subroutine and can only be used within that subroutine
global variables
can be used at any point within the whole program
local variable advantages
- saves memory (only uses memory when needed)
- easier to debug (as can only be changed within the subroutine)
- can reuse subroutine with lv in other programs
global variable advantages
- can be used anywhere
- makes maintenance easier as they are only declared once
- can be used for constants
constants
a location in the memory that stores data and does not change value as the program is run e.g pi
>
greater than
<
less than
> =
greater than or equal to
<=
less than or equal to
==
equal to
!=
not equal to
arithmetic operators
- add(+)
- subtract(-)
- multiply(*)
- divide(/)
- exponentiation(^)(**)
modulo division/modulus
- MOD(%)
- outputs remainder from the last whole number
integer division/quotient
- DIV(//)
- outputs whole number
logical operators
- true or false
- and or not
character
a data type e.g letter, number, punctuation symbol
string
a sequence of characters e.g hello
integer
whole number e.g 4
real/float
decimal number e.g 4.5
boolean
an answer that only has two values
casting
converting the value of a variable from one data type to another
array
a static data structure that can hold a fixed number of data elements (same data type)
what is the index of the first element in an array
0
traversing an array
scooby = [“velma”, “daphne”, “fred”]
for name in scooby:
print(name)
inserting a value
array is fixed but you can change the value of elements that already exist by overwriting
e.g scooby[0] = “shaggy”
deleting a value
can’t actually but can overwrite them as blank instead
searching an array
for name in scooby:
if name == “fred”
print(name)
outputs freds name
2D array
- table
- same data types
- row first then column
- e.g scooby = [[“scooby”, “brown”],
[“shaggy”, “green”]]
print(scooby[1][0])
output = shaggy
searching 2d array
for row in scooby:
for name in row:
if name == “scooby”:
print(row)
output = scooby, brown
records
- can store data of different data types
- made up of information about one person or thing
- each piece of info in the record is called a field
key field
- unique data that identifies each record
- field (each row name)