Thursday, February 3, 2011

Feb 2-3

Today I am continuing onto chapter 5. Starting with fruitful functions. When working with python on the incremental development I've noticed that the distance program they tell you to program into python is basically the same as the real life formula when you code like:
def distance(x1, y1, x2, y2):
...     dx = x2 - x1
...     dy = y2 - y1
...     print "dx is", dx
...     print "dy is", dy
...     return 0.0
the d in this code is referring to distance then both the x and y used in this code stands for the x-axis and y-axis of a graph. This is a very interesting program to me and very easy to understand.
When working on getting the area of a circle i had some difficulty until I finally understand that what they was saying was to instead of start making a new program you just have to change the program you last did with distance to:
def area2(xc, yc, xp, yp)
...      radius = distance(xc, yc, xp, yp)
...      result = area(radius)
...      return result
so basically i had to fully change the distance program to make it fit the area of a cirlce program.
When it comes to boolean functions, they are pretty easy to understand when its basically a yes/or kind of question. At this point it told me to code a small script and when I finished it came up to have an error. What caused the error which took me forever to get why it was an error was instead of using a 0 in:
def is_divisible(x, y):
        return x % y = 0
I instead used an O on accident without even noticing.
When working with triple quotes, I've noticed that they work the same as just using one thing of quotes. The triple quotes still prints for example
"""Hello, world!""" when you can still use "Hello,World!" to get the same result.

2 comments:

  1. What is different about triple quotes is that they can span multiple lines and include newline (return) characters.

    There is still a mistake in your is_divisible function, it should be:

    return x % y == 0

    Do you understand why?

    ReplyDelete
  2. Yes I do it was a type-o so thats why it came out wrong on here. My bad

    ReplyDelete