IPND in Three Days or Bust - Wrapping up Project 2

Received my Project 1 submission at 1:09 am, but an little error on my part caused it to return. I tried to make on ordered list a child to a paragraph, and that is not allowed. Fixed a couple other things. The project is on GitHub at https://www.github.com/thechronicmonster if interested.

Sunday 7/19 9:58 am

Working on a procedure to decide if a day is a weekend or not. It looks something like this:

def weekend(day):
if day[0] == "S" and day[-3:] == "day":
return True
else:
return False

Using While Loops to create a countdown to blastoff:

def countdown(x):
while x > 0:
print x
x = x - 1
if x == 0:
print "Blastoff!"

Another solution to the find the biggest among three numbers is embed a function within a function (not quite recursive, these are two different functions).

def bigger(a,b):
if a > b:
return a
else:
return b
def biggest(a,b,c):
return bigger(a,bigger(b,c))

Today was derailed by a dehydrated bunny trapped in the garage. Thankfully the poor mammal decided to quit hiding and laid down near the doorway. I think we successfully nursed it back to its habitat, but the stress of seeing that little creature in such straights really capitalized my attention, today. Plus, the monster came back so once the bunny was satiated the monster became the center of attention. So, after an hour long bike ride/playground break and one and one-half gatorades I am now ready to take on Work Session 4 before calling it a night.

Time to work on creating a median finding function...

8:45 pm

It is now 10:51 pm and I have come up with a (probably terrible) solution to finding a median number given three numbers. So excited.

I started with the bigger and biggest functions and created mirrored smaller and smallest functions. My thought was if I don't know how to pick out the median I do know how to pick which numbers aren't the median. This works for three number medians. Once we take this problem to the next level my little solution breaks...but we're celebrating. The problem I ran into was when two of the inputs were the same so I created a function same that takes three inputs and checks if any inputs are the same and returns the double input. It looks like this:

def same(a,b,c):
if a == b or a == c:
return a
if b == c:
 return b

def median(a,b,c):
x = smallest(a,b,c)
y = biggest(a,b,c)
z = same(a,b,c)
if z != None:
return z
if a != x and a != y:
return a
if b != x and b != y:
return b
if c != x and c != y:
return c
if a == x and a != y:
 return a
if b == x and b != y:
 return b
if c == x and c != y:
return c

Modular code: code that separates the data from its visual presentation such that one may be changed without effecting the other. 

Best practices for writing code:

  1. Break a big task into smaller pieces
  2. use functions that have already been written
  3. write new functions to solve pieces of the bigger problem
  4. put the pieces together to solve the bigger problem

Systems thinking can be accomplished in a 5 step process:

  1. Understand the requirements of a problem. i.e. what are the inputs and what should the outputs be
  2. Plan an approach to solve the problem
  3. re-familiarize yourself with code that you've wrote so that it may be useful in solving the problem.
  4. Write new code to solve the other pieces of the problem
  5. Put all the pieces together.