T7 - Programming fundamentals Flashcards
data type
The kind of values that can be used in a data item
eg of data types
integer, float / real, character, string, Boolean
eg of arithmetic operators
+, -, *, /, ^, MOD, DIV
The operator DIV
is used for integer division, also known as quotient
MOD (modulus) is
used to find the remainder when dividing one integer by another
data type and memory
Data types will determine the amount of memory allocated
constants in pseudocode n python
const
-snakecase inpython
Snake case
- separated with an underscore and capital letters
Use of snake case
- shows programmer that it must stay the same
-prevents the value from being changed accidentally by a part of code
Constants
- won’t change its value whilst program runs
- can be changed by a programmer before the program is compiled or translated
Casting
- converts data types
Pseudocode:
converts a string s to an integer
int(s)
Inputs from the user
are strings
Concatenating means
joining together:
The concatenate operator is
+
- used to join together strings
pseudocode: converts a string s to a number with a decimal point
float(s)
pseudocode: converts an integer or floating point number x to a string
str(x)
pseudocode: converts a string (e.g.”True”) to a Boolean
bool(s)
pseudocode: ASC(‘a’)
evaluates to 97, using ASCII
pseudocode: CHR(97)
evaluates to ‘a’
String handling functions:
Python
= variable.len
Pseudocode: string length
str.length
Pseudocode: letters from right
str.right(n)
Pseudocode: letters from left
str.left(n)
pseudocode substring
str.substring(start,end)
all uppercase
.upper
all lowercase
.lower =
Comments:
to describe the purpose of the program
to state the author of the program
to explain what the code does
comments - python
Python - comments start with #
comments in Pseudocode
- start with a double slash //