1/63
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Flowchart
A diagram that shows the step by step instructions of an algorithm using standard symbols
Pseudocode
A method of writing up a set of instructions for a computer s program using plain English
What is the most common input device?
The keyboard
What command in Python allows user input?
Input
Example of an input statement
Input(“prompt”
Input(“prompt”)
What is the prompt?
A message displayed on a users screen before they input their answer
What is the output function in Python?
Example of a print statement
Print(“ hello, world!”)
Output data must be a _____ before we can print it
String
If we want to print data which is not a string, then we must…
Cast it to a string
What are the data types?
Boolean (true/false)
Integers (whole numbers - 1,3,2828)
Float (decimal numbers- 3.6 7.6288)
String (text- “hello world”)
Data types determine
How data is stored and what you can do with it
Casting
The process of converting a value from one data type to another, such as turning a string into an integer or vice versa
All input’s must come out as a string and must be
Converted to other data types
Casting to a string can be done using what function?
The str function
Eg; str(3) gives “3”
Int(3.4) would result as
The number 3
Type coercion allows us to…
Operate on data of different types
When adding two numbers of different data types, type coercion…
Allows one of the types to be automatically cast so that the operation can be completed
When working with a float and an integer, the final result will be a
Float
When working with a string and an integer, the result will be a
String
What is a variable?
A named memory location that holds data that can change while a program is running
What is a constant?
A named memory location where the value remains unchanged throughout a programs execution
The value of a variable can ….
Change whilst a program is running
To use a variable, we give it an _____ and a _____
Identifier, value
Operators are
Symbols that represent a specific function within a program
Relational operators
Operators which compare two values and produce a true or a false result
Boolean operators
Operators which perform logical operations and always results in a true or false value
What does MOD do?
Gives the reminder of a division. Eg:
5 MOD 2=1
What does DIV do?
Returns the quotient (whole part) of the division, Eg:
5 DIV 2 = 2
3//2
1
3/2
1.5
What is the assignment operator
=
Selection
A programming construct where a program makes a decision to run a specific block of code based on a condition, which can either be true or false.
What are the methods of selection
Else, if, Elif statements
If statement
Conditions can be tested using this statement, for example:
If( x > 50 ):
Else statements
We can add an else statement after an IMF statement, for example:
Else:
This will only execute the following block of code if the condition is false.
Elif statements
These statements can be added between if and else blocks.
they will execute the condition before it was false, and the condition following it is true.
Example of using an if statement
IF condition 1:
action 1()
Example of using an elf statement
Elif condition2:
Action2()
Example of using the else statement
Else:
action3()
Iteration
The process of repeating a set of instructions or code in a program, also known as a “loop”
Iteration techniques
while loop
Repeat until
For
Do while
A flow diagram for iteration uses a
Diamond shape
What is definite iteration?
a block of code will repeat a known number of times
What is indefinite iteration?
a block of code will repeat whilst a specified condition is true
What would an example of definite iteration be?
A for loop will execute an indented block for each value in a list of values
What would be an example of indefinite iteration?
A while loop will continue to execute an indented block of code while a certain condition is true
Example of a for loop
For i in range(0,10):
action1()
action2()
Example of a while loop
While condition:
action 1()
action 2()
Listing
A data structure which holds a finite, ordered collection of items under a single identifier
What’s the main difference between listing and arrays?
Lists can hold data values with differing data types whereas arrays tend to elements of the same data type
list example
my_list = [1, "apple", True] # works fine
it holds multiple data types
Array example
my_array = array.array('i', [1, 2, 3])
‘i’ indicates integer
What do we use to add to an array?
Append
Example code for adding to an array
Myarr.append()
What would list[5].append(3) do?
Add 3 to the 6th inner list
The [5] would be the sixth list because
0 1 2 3 4 5 is six values altogether
What are the uses of 2D lists/arrays?
To represent a 2D surface, for example- a chess board
code to access an individual list from a 2D list
List= my2Dlist[4]
List[5][0] would allow us…
To access an individual element, this would give us the first element [0] of the sixth list [5]
2D list/array
A data structure where lists are filled with other lists
What is abstraction?
the process of simplifying a problem by removing all unnecessary details to focus only on the essential ones
What is defragmentation?
the process of reorganizing data on a hard disk drive so that all the fragments of a file are stored in a single, contiguous block of space
Whats the point of casting?
to convert data types for operations