lunes, 27 de abril de 2015

#WSQ16 cars cars.

I did this WSQ with help of this blogpost.

with this WSQ I learned how to open files in python. and do different things with them.

"open() returns a file object, and is most commonly used with two arguments: open(filename, mode).
>>>
>>> f = open('workfile', 'w')
>>> print f
<open file 'workfile', mode 'w' at 80a0960> 
The first argument is a string containing the filename. The second argument is another string containing a few characters describing the way in which the file will be used. mode can be 'r' when the file will only be read, 'w' for only writing (an existing file with the same name will be erased), and 'a'opens the file for appending; any data written to the file is automatically added to the end. 'r+' opens the file for both reading and writing. The modeargument is optional; 'r' will be assumed if it’s omitted." - Python.org 

I reversed engeneered Efrain's code to see what he tried to do in order to learn.

LINK TO CODE.


lunes, 20 de abril de 2015

#Final Dash

To finish this course I:

1. Will finish WSQ´s by the end of this week, hopefully
2. Will finish my Masteries by the end of the month, I'll try to make mostly videos.
3. Study off of old exams to study for the final.


WSQ14, calculating e

For this program I changed my float to a String, and in order to print the exact amount of decimal points I used it as a list, and I printend just the values I wanted (learn more):

Code:
https://github.com/EduardoMerino/Sharing-for-Class/blob/master/wsq-14.py

Reference links:
https://docs.python.org/3/tutorial/introduction.html#lists

http://en.wikipedia.org/wiki/E_%28mathematical_constant%29


miércoles, 8 de abril de 2015

#Mastery21 use of recursion

You use recursion in functions for repetitive algorthms. Basically griting a function inside itself for a sort of loop, making your code smaller and cleaner.

this program is grat example, I have 2 functions and they repeat inside each other, I could have made different functions but they would have recursion in that way. 

 my WSQ12 is also a great example of recursion.
in this case the program uses de function gcd to determine the greatest comon divisor, and ans is the gratest common divisor itself, in case that the numbers given by the user are not the same (not x==y), the fuction will call itself but with some changes:

else:
if(x>y):
ans=gcd((x-y),y)
else:
ans=gcd(x,(y-x))
return ans


other examples of recución are: palindromesstandard deviation

#Mastery09 Basic types.

there are 3 basic tipes in python:

NUMERIC TYPES:

your basic numbers used for math, algebra, and to calculate various values.

The most basic are intergers and floating point numbers.

intergers, used with the function int( ). are numbers with no desimal poin.
and floating point float( ). support decimal point.

and ther is also:

TEXT SEQUENCE TYPES:

witch is srtings. "Textual data in Python is handled with str objects, or strings. Strings are immutable sequences of Unicode code points. String literals are written in a variety of ways:"(python.org)

and finally:

SEQUENCE TYPES:

witch is lists, tuples, and ranges. witch are agroup of balues, (it could be a mixture of values for lists and touples). In a group or package used as a single object, with many values inside.

#Mastery22 What type of repetition should I use?

When programing, the use of repetition is very usfull, it makes a program shorter, and more efficient.
But there are many types of repetition in Python, witch one should I use?

Here is a qwick guide with my recomendations.

WHILE:

While loops are used when there is a factor that whill be changin 'n' times and you want to stop when said factor changes, also if the user is in control of the loop, if the factor is proned to change you use a while loop. (Learn More about While loops).
examples:

x=0
while (x==0):
     print("Hi")
     x=int(input("stop?, 0=no 1=yes")

Another example.



FOR:

For loops are used when you want your process to loop for the amount of time inside a range, When the amount of times it will loop is already pre-determined, either by the user or the programmer, you use a For loop.(Learn more about For loops).

1 example.


RECURSION:
Recursion is used when a function will repeat inside itself, func-ception, it will till a certian answer is reached, this one is tricky because you need to build the fuction with recursion in mind.
My most recent WSQs have been using recursion, so why dont you check that out?.



#Mastery26 Strings

Besides numbers, Python can also manipulate strings, which can be expressed in several ways. They can be enclosed in single quotes ('...') or double quotes ("...") with the same result.(Click here to learn more).

You can turn any value into a string with the str( ) function (like seen in this program). you can also use string inputs. 
str(input()). 

When you make a sum of strings it will make a concatenation:

1+1=
2
"1"+"1"=        Concatenation.
"11"
"Hi "+" I´m "+" George"=    Concatenation
"Hi I´m George".

String can also be multiplied as seen in this program.

#Mastery24 Tuples



A tuple is the same thing that a list in python. Click here to learn about lists.
But thiferent from lists a tuple uses the "( )" signs to enclose the group rather than the "[ ]" of the lists.

The main difference it has is that Tuples CAN'T BE MODIFIED, so al the append, erase and replace functions that work with lists Wont work with a touple. Click here to learn more about Touples.

#Mastery23 lists

Learn to use lists.