1/18
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
functions
Avoid repeated code
Break program into smaller parts
Simplify problem solving process
Make program more readable
Functions = helps make karel turn right
Top Down Design/Decomposition
Decomposing program into readable tiny parts
- Big messy functions < small simple functions
Helps solve large complicated problems
Lets us collab by splitting problem into subproblems that can be solved independently
Comments on Code
Good style = clean + reasonable
Notes explaining the code to reader
i. Preconditions = must be true before function
ii. Postconditions = must be true after function
Abstraction
"Abstracting away" complex info to be relevant
Defines program steps, but not how exactly
i. write functions to "abstract away" picky details
AP| = Application Programming Interface
Set of tools for building programs
Karel = API built by Python that abstracts her
code
For Loops
repeated fixed # of times
for i in range (#): move()
Bug
Mistake in Code
Conditionals
function returning a T/F answer
Front clear? Balls present? Facing east?
If/Else Statements
For different worlds: specific < general
While Loops: repeat code IF condition is true
Control Structures
Ask Questions: If & If/Else Statements
Repeat Code: For & While Loop
Debugging Strategies
Pay attention to details (typos…)
Question all assumptions
Error Types
Syntax: program no run
Runtime: program run then crash
Loop: program run then confused (no message)
Algorithms?
Step by step set of instructions to solve problem
All algorithms made with
Sequence, Iteration, Selection (efficiency + clarity)
Sequence
step by step execution in given order / natural program flow
Iteration
repeating instructions (for/while loops)
Selection
choosing which instructions to do (if & if/else statements)
Problem Solving Process
Natural language < Pseudocode < Program
Pseudocode
Writing out algorithm plainly to help write program
Parameters : color[“red”]
Inputs into functions
we can pass parameters to a function to make it do specific things