2.2 Programming Fundamentals Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is variable?

A

Variable - A variable is a value stored in memory that can change while the program is running.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Casting and why might it be useful?

A

CAsting - Converting data types

This process is known as casting. The following examples convert a string to an integer and an integer to a string:

str(68) returns “68”

int(“54”) returns 54

float(“5.4”) returns 5.4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the five main data types?

A

Each data type is allocated a different amount of memory

Integer - A positive or negative whole number used when arithmetic will be required

Real / Float - A positive or negative decimal number

Character - A single alphanumeric

String - Multiple characters joined together [n.b. use this for credit card numbers]

Boolean - two inputs(true and false)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is string manipulation?

A

word = “Hello World”

length = len(word) = 10

  • *word[0:3]** = “Hel”
  • *word[-3:] = “rld”**
  • *print word[3:] = “lo World”**
  • *print word[:-3] #get all but the three last character​**
  • *word.upper() = “HELLO WORLD”**
  • *word.lower() = “hello world”**
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a constant?

A

Constant - A value which remains fixed as does not change whilst the program is running. It must be set at design time when the program is first written.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a sequence

A

Sequence is executing one instruction after another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Selection

A

Selection is program branching depending on a condition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Iteration?
What are the 3 types of loops?

A

Iteration, sometimes called looping, is repeating sections of code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the three common Boolean Operators?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does casting allow for?

A

It allow Sub-programs to recieve data in the format they were expecting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is ASCII conversion?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the stages to write data to a file?

A
  • Open the file for creating/overwriting or appending to a file

My

  • Write the data to a file
  • Close the file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the stages to read data from a file?

A
  • Open the file for reading data
  • Assign a boolean variable to “false” to indicate the end of file is not reached.
  • While the end of the file is false and the search item is not found:
  • Read data from the file
  • If the data matches what is being searched for, assign the data to variables or output.
  • Check if the end of the file has been reached and assign the Boolean variable to “true”
  • Close the file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are records?

A

Data in data bases are stored as records.
Each records contains a number of fields and each field has its own data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a record structure

A

A record structure:

  • A collection of related fields
  • Each field is a variable
  • Each field in a record can have a different data type.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How are records stored in text files?

A
  • Stored on the secondary storage
  • Used to store data when the application is closed.
  • Useful for small volumes of data. E.g. configuration files.
  • Each entry is stored on a new line or separated with an identifier such as a comma or tab.
  • Can require a linear search to find/read data which is slow (if there is no order to the data or record structure).
  • Structured text files E.g. CSV, XML & JSON are popular for storing and exchanging data between applications
17
Q

How are records stored in Arrayas and Lists

A

Stored in RAM.
Used to store data when a program is running.
Useful for small volumes of data an algorithm is using.
Can be single or multi-dimensional allowing for tables of data to be
stored.
Uses indexes to refer to data items.
Efficient algorithms or linear searches can be used to find data

18
Q

How are records stored in databases?
What is the records structure?

A

• Often stored on remote servers.
• Often used to store data shared by many users, e.g. ticket booking
system.
Data is stored in records and fields.
Uses advanced data structures to store data efficiently.
• Uses very efficient algorithms to search and sort data executed on
the servers.
More secure than text files.
• The order of the fields in the database in independent of the code

19
Q

What is SQL

A

There are three commands you need to know:

SQL is used to create, delete, modify and manipulate records in a database

The basic commands include:

  • SELECT which fields to be returned. * can be used to indicate all fields.
  • *- FROM which table. Databases can have more than one table, each with their own unique name.**
  • WHERE records meet a condition. Like can be used as a wildcard.
20
Q

What is an Array?

A

An array is a series of memory locationseach of which holds a single item of data, but with each location sharing the same name. All data in an array must be of the same data type

We can do that by allocating a contiguous part of memory to storing that data.

Our program will know where in memory out array starts.

It uses a index relative to this start point to allow us to easily access the arrays contents.

21
Q

What are 1-dimensional Arrays?

A
22
Q

What are two-dimensional Arrays?

A

You can visualise a two dimensional array as looking like a table with two sets of indexes. One index for the rows, another for the columns.

print(countries[0][0]) creates “Angola” and 1246700

23
Q

What are the two types of sub programs

A

Procedures

  • Carry out a task & DO NOT RETURN A VALUE
  • Provide structure to code making it easier to read

Functions

  • Carry out a task AND Return a value
  • Create reusable program components
24
Q

What do sub-routines look like in flowcharts?

A
25
Q

What can sub-routines do?

A
  • Larger programs are developed as a set of sub-programs called subroutines
  • Structuring into sub-programs makes the code easier to read and debug
  • Functions return values and create reusable program components
  • Each sub-program can be easily tested.
  • Sub-programs can be saved into libraries and reused in other programs.
26
Q

How do you generate random numbers in Python?

A

For Python:

  • *Import random**
  • *a = random.randint(1,6)**

For OCR ERL:
myVariable = random(1,6)

27
Q

What are the three basic programming constructs?

A

Programs are designed using common building blocks. These building blocks, known as programming constructs, form the basis for all programs.

There are three basic building blocks to consider:

  • sequence
  • selection
  • iteration

Sequence is the order in which instructions occur and are processed. Selection determines which path a program takes when it is running. Iteration is the repeated execution of a section of code when a program is running.

There are two types of iteration:

  • count-controlled iteration
  • condition-controlled iteration

All programs use one or more of these constructs. The longer and more complex the program, the more these constructs will be used repeatedly.

28
Q

What are the five main data types?

A
29
Q

What are global and local variables?

A

Global and local variables

A global variable is one that can be accessed and changed throughout the program. Usually a programmer has to declare that the variable is a global. For example:

global ID = 75

Local variables are confined to a loop or subprogram. This has the advantage of the programmer being able to use the same variable names again and again for different purposes.

When using global variables, a programmer must be careful not to use a local variable with the same name. If this happens, the value of the global variable will be changed, causing the program to produce unexpected results.

30
Q

What is:

  • Len function
  • Cocatenation
A

Length

The length of a string can usually be determined using the len statement. This gives the length as an integer.

len(wordOne) - would give the answer eight, as there are eight characters in the word “Computer”

Concatenation

To concatenate strings means to join them to form another string. For example:

sentence = wordOne + “ “ + wordTwo - would give “Computer Science”

Alternatively, a string can be lengthened by adding more characters. For example:

wordOne = wordOne + “ Science” - would result in the value of wordOne becoming “Computer Science”

31
Q

Why and How do you open a file?

A

Opening and closing files

A file must be open before a record can be read from or written to it. To open a file, it must be referred to by its identifier, for example:

file = openRead(“scores.txt”)

This would open the file scores.txt and allow its contents to be read.

file = openWrite(“scores.txt”)

This would open the file scores.txt and allow it to have data written to it.

file.close()

32
Q

What is a Record?

A

• A collection of related fields.
• A field is a variable.
• Each field in a record can have a different data type.
• Note the dot syntax when using records: recordField
e.g. car1.Make

33
Q

What is Select, From and Where?

A

SELECT which fields to be returned. * can be used to indicate all fields

  • *FROM which table. Databases can have more than one table, each with their**
  • *own unique name**

WHERE records meet a condition.

LIKE and % can be used as a wildcard
Example SELECT name, age, iq FROM person WHERE name LIKE ‘FIS’

Example:

SELECT name, population FROM world WHERE name LIKE “A*” or “B*”

34
Q

What does LIKE do?

A

Use it to find data within the data so Names like “A*” This would return all names that have A*