|Previous Lecture||Lecture 3||Next Lecture|
Lecture 3, Tue 01/14
Git, Functions, Loops
Three key aspects of functions
- Declaration (what are the inputs, outputs?)
- Definition (actual code for achieving the desired behavior)
- Function call (using function)
- Local vs. global variables
Designing nested loops
- When do we need a loop?
- When do we need a nested loop?
- Checking for limits
- Practice with ASCII art (also topic of lab02)
Math Puzzle One of the powers of computing is being able to do a brute-force search for a solution to a problem. Trial and error works just fine for some problems. In fact, computers can be especially good at such problems. Consider this:
Horses cost $10, pigs cost $3, and rabbits are only $0.50. A farmer buys 100 animals for $100, How many of each animal did he buy?
Write a program to do this.
- Dr. Wang’s notes on loops: