3.3-3.4 Notes
Variables, Assignments, and Data Abstraction
Notes | Hacks | Grade |
3.1-3.2 Notes | 3.3-3.4 Hacks | |
3.3-3.4 Notes | 3.3-3.4 Hacks | |
3.5-3.7 Notes | 3.5-3.7 Hacks |
Mathematical Expressions and Strings
Algorithms
A set of instructions that can accomplish a specific task
Three components of an algorithm
- Sequencing: Algorithms do task in the order of specification
- Selection: Helps choose two different outcomes based off a decision
- Iteration: If a condition is true, then the code can repeat
Two different ways algorithms can be represented
- Flowcharts: The steps of an algorithm are represented by shapes and arrows
- Pseudocode: A blend of human language and coding format
Arithmetic Operations
Basic Operations
Addition is represented by +
Example: num1 = 2 + 1
which would make num1 = 3
Subtraction is represented by -
Example: num1 = 2 - 1
which would make num1 = 1
Multiplication is represented by *
Example: num1 = 2 * 1
which would make num1 = 2
Division is represented by /
Example: num1 = 2 / 1
which would make num1 = 2
Remainder is represented by MOD in psuedo code (% in python)
Example: num1 = 5 % 2
which would make num1 = 1
Order of operations applies
Variables
- Numerical value stored in a variable
- Value of another variable stored in a variable
- Result of an operation stored in a variable
- Result of a procedure call stored in a variable
Sequence of variables is important
String
A collection of characters. Characters can be anything from numbers, letters, spaces, etc.
Certain procedures can be used to affect string
Examples:
len()
to find the length of string
concat()
returns the strings as a concatenation of multiple strings
lower()
to convert to lowercase