2.2 Programming Fundamentals Flashcards
What is variable?
Variable - A variable is a value stored in memory that can change while the program is running.
What is Casting and why might it be useful?
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
What are the five main data types?
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)
What is string manipulation?
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”**
What is a constant?
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.
What is a sequence
Sequence is executing one instruction after another
What is Selection
Selection is program branching depending on a condition.
What is Iteration?
What are the 3 types of loops?
Iteration, sometimes called looping, is repeating sections of code.
What are the three common Boolean Operators?
What does casting allow for?
It allow Sub-programs to recieve data in the format they were expecting.
What is ASCII conversion?
What are the stages to write data to a file?
- Open the file for creating/overwriting or appending to a file
My
- Write the data to a file
- Close the file
What are the stages to read data from a file?
- 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
What are records?
Data in data bases are stored as records.
Each records contains a number of fields and each field has its own data type
What is a record structure
A record structure:
- A collection of related fields
- Each field is a variable
- Each field in a record can have a different data type.