Saturday, November 30, 2013

Introduction to Computer Science 11.29.13 23:26

I restarted the class on computer science from Udacity this past week. So far this course discussed the difference between a toaster and a computer in that a toaster is designed to do one thing while a computer can do anything we program it to do. A program is a code that tells the computer what to do in a given situation. I also got to do a little bit of programming in Python which is the language they use for the course. We started out with arithmetic, typing in print 1 + 1 and running it in the interpreter produces the result 2 . The print function is a way to see what the code we built is doing. Then it moved on to assignment statements. Typing in any word (name for example) an equals symbol and an expression assigns that expression to that word so if we write name = 5 * 3  and then print name it will evaluate to 15.

So lets say we wanted to print out more than just numbers, this is where we need to use strings. To create a string we could just use print 'This is a test' and the output would be This is a test. To create a string it needs to have quotes or double quotes on each side so 'the', "isn't" and '"simple" she said.' would all be valid strings. As long as the string starts and ends with the same type of quote it will work. Simple enough, but what if we have a really long string and we don't want to type it out each time? Then we could assign the string to a name and just print the name. For example: einstein_quote = '"Education is what remains after one has forgotten what one has learned in school." Albert Einstein' we can then run print einstein_quote and the string "Education is what remains after one has forgotten what one has learned in school." Albert Einstein will be the result.  

This brings us to another question, what if we have an entire page as a string and we want to find where a specific word or link first appears? We can use the find function, so starting with the string we just used we could then write einstein_quote.find('one') and the output would be the location of the first instance of the word one in our string. Of course we would have to print that piece of code to actually see the location as a number. I'm going to explain this using a shorter string,  'one' for example, if I typed in print 'one'.find(n) I would get 1 as the result because the location is initialized by numbers starting at zero and n is the second letter in the word one. We could type print 'one'[1:] and this would result in ne, because it would print starting from position one through the rest of the string. If we typed print 'one'[1:2] we would get n because the end point (2 in this case) prints up to but not including that position. We could also write print 'one'[:2] and get on, because it would display from the start of the string up to position 2.

So why and how would we use this? Well, for lesson one the goal is to be able to extract a link from a webpage. Let's go back to our einstein_quote string and say we wanted to print just the part one has forgotten what one has learned in school. we could write some code to do this as follows.

first_one = einstein_quote.find('one')
end_point = einstein_quote.find('.') + 1
print einstein_quote[first_one:end_point]

This should produce the result we are looking for. The reason the second step includes a + 1 is because the end point of an index (the [:] used to show parts of a string  ) prints up to that position and we want to include that position.

Thursday, November 21, 2013

Algebra 11.21.13

This past week I reviewed graphing basics and how to find the distance between two points. Let's start with some graphing basics. Points on a graph are denoted (x,y) where x is the distance a point is from the origin (0,0) on the x or horizontal axis and y is the distance from the origin on the y or vertical axis. A graph has 4 quadrants. Points in quadrant 1 will have both a positive x and y value so (x,y). Points in quadrant 2 will have a negative x and positive y (-x,y). In quadrant 3 both the x and y values are negative (-x,-y) and in quadrant 4 the y value is negative while the x value is positive (x,-y). It is important to note that while a graph will not show all the numbers the x and y axis extend indefinitely in both the negative and positive directions.

We can find the distance between two points using the Pythagorean Theorem a squared plus b squared = c squared where c is the hypotenuse of a right triangle. No matter which two points we look at they all can be looked at as being a part of a right triangle. So if we were going to find the distance between the point (1,2) and (2,4) we need to look at the big picture. The distance between the two x coordinates 1 and 2 is one and the distance between the two y coordinates 2 and 4 is 2. 1 squared is 1 and 2 squared is 4, one plus 4 is 5. Then we take the square root of 5 to get the distance between those two points. So the distance formula is      
                               (x2x1)2+(y2y1)2        Distance =      √

Mandarin Chinese 11.21.13

I started the Rosetta Stone Mandarin Chinese course today. So far I'm having trouble pronouncing some of the sounds but I'm starting to grasp word meaning. So here are the words I remember as close as I can get to what they sound like to me.

nu ren - woman
nan ren - man
nu hi zi - girl
nan hi zi - boy
you yong - swim
pao bu - run
hu - drink
ni hao - hello
si chen - goodbye
kan - read
shu - book
shuay - water
che - tea

As I learn more I will try to put in a few complete sentences.

Friday, November 15, 2013

Algebra 08.04.13

An equation is two expressions that are set equal to each other. Conditional equations, identities, and not equations. A Conditional equation is such that its truth is dependent on which number x stands for. For example 2x+1=5 is only true when x = 2. An Identity is when both sides are exactly the same so 3n+1=3n+1 because when we simplify we get 0=0. x-3 and 2/x +1= 2/x +2 are not equations simply because they do not equal anything or are false.