2 - Programming Flashcards
What are data types? Give some examples of some:
-data types describe the different types of data being used, and defines the range of values a variable may take
-int, real, bool, char, string
in python, real numbers are called floats
Why are data types needed?
-so the computer knows what operations it can perform on it
-it allocates the necessary amount of memory to optimise the program
in python, real numbers are called floats
What is a variable?
named identifier that holds a value in memory that can change
What is a constant, and what is it used for?
-named identifier that is given a value when initialised and holds it in memory, and doesn’t change throughout the program
-used to reference known values like pi
Define declaration/initialisation:
-naming a new identifier for the first time
-then assigning it a value
In Python, both are usually done at the same time, but some languages (like VB) do it separately
What is an identifier?
a name for a variable, constant, or subroutine
Why should you give meaningful identifier names?
-meaningful identifier names describe the purpose of the variable
-makes the program easier to interpret/debug
What are the 3 programming constructs?
-sequence
-selection
-iteration
What is sequence in programming?
executing 1 instruction after another (imperative programming)
What is selection in programming?
statements that change the flow of a program based on conditions that are met (branching)
What is iteration in programming? Describe the 3 types:
repeated execution of a section of code
for - count controlled
while - condition checked at start, may never run
repeat until - condition checked at end, always runs once
The bottom 2 are condition controlled
What is nesting?
putting a statement inside another with selection/iteration
Name 3 types of arithmetic division and give their Python symbols:
-real division, just normal ÷
/
-integer division, DIV, division that returns the integer part of the result
//
-remainder division, MOD, returns remainder
%
Name the boolean operators:
NOT
AND
OR
What are data structures?
an abstract idea of how to store and access data in a computer system
Why are data structures described as abstract?
-the computer memory doesn’t actually know it is a list, it just stores it in memory as it usually would
-it just makes it easier for the programmer to read/access
What is an array?
a data structure (1 or 2 dimensional) comprised of a set number of cells containing data all of the same type
How do you access data from a 2D array?
-the first square bracket indicates the list you want to access from the 2D array
-the second square bracket indicates the item from the previously specified list
remember indexing starts from 0