Computational Thinking (II) - Programming Flashcards
How many programming data types are there?
5
What do data types do?
Store data as different types
What happens to memory with data types?
Each data type is allocated a different amount of memory
Why is it important to use the correct data type?
The code is more memory efficient, robust (hard to break) and predictable when the correct data types are used
How can programming languages be typed?
Weakly typed or strongly typed
What are the characteristics of weakly types programming languages?
Weakly try to convert data types to avoid errors
*Can lead to unpredictable results
What are the characteristics of strongly types programming languages?
Strongly don’t convert data types so will produce more errors
*Give more predictable results
What are the 5 main data types and what are their characteristics?
What are the memory requirements for the 5 data types?
What is casting?
Manual conversion between data types
Can be done using int(), real() / float(), bool() and str() commands
In casting, what would int(“1”) achieve?
Converts the string “1” to the integer 1
In casting, what would real(1) achieve?
Converts the integer 1 to the real 1.0
In casting, what would bool(1) achieve?
Converts the integer 1 to the Boolean value True
In casting, what would str(True) achieve?
Converts the Boolean value True to the string “True”
How is casting used with ASCII and what techniques allow it to be used?
ASCII numbers and characters can be found easily using casting
ASC() and CHR() functions are used
E.g. CHR(77) converts ASCII number 77 to ASCII character M
E.g. ASC(b) converts ASCII character b to ASCII number 98
What would be the best data types to use in the following:
What are operators?
Special characters that perform certain functions
What are the arithmetic operators?
Addition Subtraction Multiplication Division Exponentiation Quotient (DIV) Remainder / modulus (MOD)
What does the exponentiation operator ^ do?
Raises a number to a power
What does the quotient (DIV) operator do?
Returns the whole number
What does the remainder / modulus (MOD) operator do?
Returns the remainder
What do operators work on?
Integers / real data values (or a combination of the two)
What mathematical rule do computers follow?
Using BODMAS, calculate the following:
2 + 8 * 2
(2 + 8) * 2
2 + 8 * 2 = 18
(2 + 8) * 2 = 20