2017-02-06 HW

posted Feb 6, 2017, 6:56 AM by Samuel Konstantinovich   [ updated Feb 6, 2017, 7:13 AM ]
Quiz Friday
All python *not including new material Thursday*

Python Reference sheet:

Homework: (or classwork when done with all classwork)
Codingbat Warmup-1

Goal: Top-Down Design of a program

1. Go over multiple ways to solve a few of the coding bat problems. 

2. Designing a function, and breaking it up into subproblems.

Qa. What is an algorithm?

Many of the functions and programs you write are simple enough to complete without designing them. This is because you can easily understand the whole algorithm. A formula, or a simple set of if statements don't seem to require a design. 

As you write more complex code, you cannot understand the whole algorithm or process all of the consequences at once. This is why it is a good idea to DESIGN your program rather than just hack it together by writing code until it works, even though it may seem like a waste of time for now.

Your design will be in plain English, which makes it faster and easier to write than actual code. It is also easier to find errors in your logic, and faster to fix than after you have coded the algorithm.

3. CConsider the following function:  DO NOT WRITE CODE until instructed.
        Look at the ones digit, and tens digit of n. 
            When they are the same, return the value of that digit. 
            When they are different, return the sum of the digits.
        It doesn't matter if the number is a single digit, or more than 2 digits. 
magicValue(816) -> 7 #add the ones and tens digits, extra digits do not count.
magicValue(122) -> 2 #doubles only count once
magicValue(2) -> 2   #when there is no tens digit, there is really just a 0 there.

Top down design: A plain English plan for your program.

***Write out your design, and answer the questions. DO NOT WRITE CODE until you do this.***

1. TASK: Write your steps out in English, tell the steps to your rubber ducky.

Qb. There are some calculations that must be made, and it would be much easier to read code if you named the calculations by creating a function. What helper function(s) would be nice to have before you write your function?

2. Show your steps to two neighbors, and see if you both agree on each other's algorithm. Do you agree on your helper functions?

3. Write test cases for your program. Not my test cases. 

4. Write the function, and use your test cases.