IPND - Marching Forward

The weekend's experiment was a bust. A good experience, but the IPND is too robust to be properly completed in a mere 72 hours. That's good news for students. The portfolio projects themselves may be able to be completed in that kind of a time frame, but then the meat of the nanodegree is missed. So I'm adjusting my goal to one project per week. 

Stage 2: Work Session 4:

Working on systematically breaking down a problem. Going to take an input of "TITLE:" and "DESCRIPTION:" and we want it to look like

<div class="concept">
<div class="title">
title 1
</div>
  <div class="description">
  description 1
  </div>
</div>

A function is needed to convert the input to the desired output. Break big problems down into smaller parts. Create solutions to the small problems then tie it all together. The function that we create will accept a second input for the HTML. Sometimes working backwards from what you know you can do is easier. 

For this particular problem we're going to create a function called get_concept_by_number that will take the input and break it into TITLE and DESCRIPTION by number. Then we'll create two functions, one will get_title and the other will get_description. We'll use the get_title and get_description outputs in a function called generate_concept_HTML. This will output the HTML!

2.6 Structured Data: Lists & For Loops

Introduction to an object called a list. 

A string is structured data because it can be broken down into its characters. In a string a sequence of characters is contained within quotes. In a List characters are contained in an array (square brackets) and separated by commas. Lists can be accessed using square brackets and numbers. i.e. p[0] or p[2,4]. This second call will return a list of elements.

Lists can call subs of subs so if you have a list of countries

#             Name    Capital  Populations (millions)
countries = [['China','Beijing',1350],
             ['India','Delhi',1210],
             ['Romania','Bucharest',21],
             ['United States','Washington',307]]

To call Delhi type: print countries[1][1] and it will print the 1 item in the 1 list, 'Delhi'

If we want to know how many times greater China's population is to Romanias we can type:

print countires[0][2] / countries[2][2] and python will do that math.

#floored

Lists work by using two concepts: Mutation and Aliasing.

Lists support Mutation (yes they are a friend to the X-Men). This means the value of a list can be changed after it has been created

That's enough for this post..

 

 

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.

 

IPND in Three Days or Bust - Project 2 Continued

Back from my break, enjoying Men Amongst Mountains by The Revivalists. Check them out on iTunes, buy their new album. Support great artists.

And we're back from our sponsors (joking). We left off with Work Session 3 and are now ready to jump into 2.4: Control Flow & Loops: If and While. Very important skills for the developer to have in her pocket protector...

6:52 pm

While loops operate WHILE a parameter is true. If statements run code depending on certain parameters. If statements are often united with if else and else statements.

If, else statements look something like this in Python:

if (some code here):
 print/return (or do something other than print)
else:
 print/return (something else)

writing if functions to check for letters in strings and greater than/lesser than problems..and am now being warned of a Collatz conjecture problem. Sounds like a smart mathematician. 

Remember when testing with booleans that True and False begin with capital letters..

7:28 pm

challenging quiz to create a program that will take three numerical parameters and output the biggest. Sounds like a fun challenge using if/else statements.

7:47 pm

I have grown greatly as a programmer in the past eight months. Solved what Dave classified as a gold star problem in ten minutes. So there's a word of hope for new programmers struggling through understanding. You will achieve your goals, even if it does require some amount of mental frustration.

8:22 

Dave says that all programs can be wrote with arithmetic comparisons and functions (procedures) and if statements. That's quite a profound statement. There are other tools that make programming a bit simpler, I'm assuming, but what a statement to say these three things can accomplish all things in a program.

While loops syntax looks like:

i = 0
while i != 10:
i = i+1
print i

Alright, wrapped up 2.4 and can now (technically) write any code in the world...I think it's true. I know just enough to be dangerous.

8:52 pm

Forward to 2.5: Debugging

Bugs, it's a programmer's life.

I'm not sure who's Andy's partner in Debugging, but he's a natural comedian. 

Best explanation of Git I've ever heard: "Basically a big undo button."

Debugging strategy recap for those (me included) wondering what I've learned

  1. Examine error messages when programs crash (called a Traceback in Python)
  2. Work from example code (copy and paste what works and play till it breaks)
  3. Make sure examples work 
  4. Check (print) intermediate results (remember to remove print statements after debugging)
  5. Keep and compare old versions (Use a VCS like Github for greater freedom in coding)

9:46 pm

That wraps up 2.5, Work Session 4 up next..

My brain has had it for awhile so that's it.

9:53 pm