chap 8 - overall Flashcards
(16 cards)
explain each thing when explaining assignment
eg. c = a + b
- c: variable
- +: addition of a and b
- =: assignment of variable
conditional statement to get something in between value
eg. if (0 < username <10):
and & or conditional statements
eg. if ( age> 10 and age< 20):
eg. if ( age> 10 or age< 20):
when checking for discounts, always put bigger no. first
if total > 1000;
discount = total *0.2
elif total > 500:
discount = total *0.1
use of loops
use same algorithm for diff. inputs
types of loops
-for (count controlled) - knows how many times to run - doesn’t check condition
-while (pre condition) - checks iterating value before running - use for validation
-repeat until - post condition loop
basic structure of loops
-initializer- variable which controls if loop is done or not
-action
-stopping condition
-updating counter/ no. loops
define array
-a sequence of elements of the same data type
-each element has an index value
-arrays cannot be implemented on python so just think of them like list with 1 data type
difference btw 1D & 2D array in terms of memory
1D - data is stored randomly in memory cell = more comparisons to find them
2D - data is stored consecutively in memory cell = less comparisons to find them
what is a 2D list
a list made up of lists
eg.
meats = [“chicken”, “fish”, “turkey”]
groceries = [fruits, groceries, meats]
searching algorithm - linear search
-compare target value with elements from left to right until they match (can be used for sorted or unsorted list)
sorting algorithm - bubble sort
-start with 1 chosen element
-compares adjacent elements to the chosen element and swaps them if needed until it is no longer needed
-use a temporary value to swap elements
procedure
does not return value
function
returns value
parameter
variables that store the values of arguments passed in procedure/ functions (values next to defining the procedure/ function), where the arguments go
arguments
values passed in function/ procedure