Programming
No description yet. This curated deck is ready for daily study.
Card preview (10)
= vs. ==
= is assignment == is comparison or equality
Loops
condition-controlled loops: pre-conditioned is a WHILE loop post-conditioned is a DO…UNTIL loop count-controlled loops: for loop (for counter in range)
constant vs. variable
value that does not change throughout code and remains “constant” variable can change throughout the code based on input etc.
Data types
char is a single alphanumeric character string is 2 or more alphanumeric characters integer is a whole number value float is a floating point or decimal number boolean is a true/false, yes/no or on/off value
Programming constructs
Assignment: an assignment statement allows us to place a value inside a variable Sequence: the order of programming statements eg. must input name before printing Selection: making decisions in code or the occurrence of something as the result of a previous result or statement eg. if statements Iteration: repeating or looping one or more lines of code eg. for loop while loop do while/until loop
Data validation
Main: Range, Type and Presence Range check: check for data input to between a minimum and maximum value (limit looks for only min or max) Length check: check that number of characters doesn’t exceed or precede a certain value (usually for strings or passwords) Type check: check that data input is the correct data type Presence check: checks that input has been received Format check: check for input in certain format (date in dd/mm/yy)
Flowchart symbols
Terminator (start/end) = rounded square/oval Input/Output = parallelogram Process = rectangle Decision = Diamond
Operators: Arithmetic: \+ - * ** / // % Assignment: \+= -= *= /= %= **= Boolean: “and” “or” “not” Relation: < > <= >= == !=
Arithmetic: \+ addition - subtraction * multiplication ** exponent / Floating-point division (e.g. 5 / 2 = 2.5 ) // Floor division (e.g. 5 // 2 = 2 ) % Modulo division (remainder - e.g. 5 % 2 = 1 ) Assignment: \+= Additive assignment (x += 5 is the same as x = x + 5) -= Subtractive assignment (x -= 5 is the same as x = x - 5) *= Multiplicative assignment (x *= 5 is the same as x = x * 5) /= Divisive assignment (x /= 5 is the same as x = x / 5) %= Modulus assignment (x %= 5 is the same as x = x % 5) //= Floor-division assignment (x //= 5 is the same as x = x // 5) **= Exponential assignment (x **= 5 is the same as x = x ** 5) Boolean: “and” All conditions must be True “or” Only one of the conditions needs to be True “not” Gives us the inverse (opposite) of the value being evaluated Relational: < Less than > Greater than <= Less than or equal to >= Greater than or equal to == Equality (in a condition) != Not equal to
Data type conversions
Everything typed into a computer console is seen as a string str() converts value in brackets into a string int() converts value in brackets into an integer float() converts value in brackets into a floating point
Totalling vs. counting
Totalling adds values together , it totals or sums values Counting counts the number of values, it counts repetitions totalling eg. totalWeight += itemWeight counting eg. itemCount += 1