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.

jueves, 26 de marzo de 2015

#Mastery04 Work

This is just a little tutorial on how to deliver work to this course via blog.

1. create your course blog:
     you can use any kind of blog that uses RSS technology (Blogger, Tumblr, WordPress, etc..)
2.Link blog to your acount:
   Follow the steps in Ken's page.
3. For every assigment make a new blog post:
     include evidence of the resources you needed and that you did the work.
4. Tag acordingly:
     use a hastag(#) or your blogs tag sistem in your post to be tracked down, use the name of the                asigment (wsq or mastery) plus the two digit number (like in this case #Mastery04).
5. Include a link to the code in GitHub:
     In this Video our teacher explains how to use GitHub. Always allow people to see your code.
6. Study.
7. Have fun.

#Mastery10 basic output

An outout is a the iformation  that goes from the cumputer to the outside world, according to Wikipedia.

the most basic of examples is the Hello world program. every programer makes one.

For this we use the print fuction, witch displays text (of any type) in the screen.

see code for hellow world here.

#Mastery18 nesting of conditonal statements:

in other words putting an if inside an if.
you can see in this program how it creates a hole new conditional statement if the first conditon is not met (an if inside an else).

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

If the first condicional is not met (the values are not the same) then ,by definition, thay are different, but they can be differnt in 2 ways (greater than and lesser than...), so a new condition has to be made. 

Its really easy, and probably you would be doing it without noticing, the import thing is that all conditionals result on something, and make shure to close them all and dont loose track. 

sábado, 21 de marzo de 2015

#WSQ12

click here for code

this program uses recursion to use a function inside itself (woah! functionception) witch isnt the first time we do that in this blog.

this program finds the Greatest Common Divisor of a pair of int. numbers.


miércoles, 18 de marzo de 2015

#WSQ11

Click here to see code

This program seen here uses fuctions in a fun way to determine weather a number is a palindrome or not.

in this program the number will count as a palindrome if it can become a palindrome, example:

11 = palindrome 

31= (31+13=44) =palindrome

28=(28+82=110)=(110+011=121)=palindrome

The only way that a number will be considered a non palindrome by this program is if it takes +30 steps to turn into a palindrome.

miércoles, 11 de marzo de 2015

#WSQ10

This program is all about lists. Click here to see the code

It has some fuctions made by me and a couple of while loops to make things easy.

I used the python documentation to help me do it. check python documentation on lists.


jueves, 26 de febrero de 2015

#WSQ09

click here for code

in this program we are doing the factorial multiplication of a number:

I crated a fuction to do so, using a counter and an accumulator within a loop. the program also uses many while and if statements, so the program ca repeat itself until the user wants to stop.


jueves, 19 de febrero de 2015

#Mastery11 how to call a fuction.

Calling a fuction its exactly what it sounds like. You are telling the fuction to act on the values you have stablished.  to call a fuction  first you must have a variable that will get the return value of your fuction.

example:

lets say you crated a fuction called: make_sum.

the fuction would look like this:

def make_sum(x,y):
ans=x+y
   return ans

so in your code you would create a varible, lets say:

the_sum =

then you write the fuction, adding the values that you want it to take.

the_sum = make_sum(2,5)

so: 
make_sum(x,y):
ans=x+y
   return ans
will become:
make_sum(2,5):
ans=2+5
   return ans

and the variable the_sum will receve the return value of:


make_sum(2,5):
ans=2+5
   return ans
wich in this case is 7.

The Fun with numbers code in here shows an example of a program that calls differnt fuctions.

note: is very usefull to create your fuctions in a separate place from the rest of the code.

miércoles, 18 de febrero de 2015

#mastery12 fuctions in python


To define a fuction you write the word def followed by the name you gave your fuction, in parethes you grite the values it will take, a colon ":" and in the folowing lines you write the steps the fuction will follow. at the end you write return and the value that it will end up giving. 

example:
def make_sum(x,y):
ans=x+y
   return ans



this program shown here uses personally made fuctions:

you can copy and paste the code from this link to try it on your own.  


Fun with number, now functions in Python.

#wsq08

this is a remake of the fun with numbers program, but this time using fuctions:

click here to see the code

check out mastery 12 to see how to make your own fuctions.





martes, 10 de febrero de 2015

#Mastery20 'for' loops

"Python’s for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence."(Original text.)

In this case the loop of for prints over the sequence of numbers given by the user. Due to the way that python sets up sequences it was real E-Z to make the user determine the way that the numbers will go up. The range of numbers is exclusive, that means that it wont include the very last númber of the sequence, I represented that in the program with a '>'. 

example: 
for i in range(0,11,5):
     print (i)
In this case the program will loop until every single value of i is printed. i is in range from 0 to 10, and it will go up by 5. Which means that it will appear: 0,5,10. 

Use of "elif"

#mastery17.
The elif statement is a conditional statement that is short for 'else if'. It goes right after an if statement and is good so you can prevent exesive identation.
This qwick program uses both the if and elif statements, as well as an final else stament.

I hope this was usefull in your if statesment programing.  

To learn more about if staments Click Here.

lunes, 9 de febrero de 2015

#WSQ07 Sum of numbers

This was quite a fun program to make. I used a While loop, you can see the code and the terminal runing in the picture, as well as a online calculator prooving that that the answer is right.

Using a While loop

A while loop is used in a similar fashin that the conditional loop, exept this will run every single time that the condition in it is found to be truth.

So you have your basic stuff. You grite your conditional inside parenthesis followed by a colon, and then you write all the code you want the program to repeat till the condition is truth in the following line with an identation.

example:

x = int(input("give me a number"))
while(x!=0):
           if(x>0):
                  print(x," is a positive number")
           if(x<0):
                  print(x," is a negative number")
           x=int(input("Change the number: ")
if(x==0):
          print(x," is cero")

In this case the program wont stop (it wont get out of the loop) untill you tipe the number "0". 

Again the Random númber program is a great exaple using the while loop.


Use of the conditional IF

The random numbers program in here shows a great example of the If conditional being used. You basically set your conditinial, write a colon, and in the next lines you write the code with an identation of all the steps that will follow beeing the conditional truth. 
example: 
x = int(input("give me a number"))
if(x>0):
           print(x," is a positive number")
if(x<0):
          print(x," is a negative number")
if(x==0):
          print(x," is cero")


Coments in Python

It's real simple. You write whatever you want to coment right beside your code, sandwitched in between two '#' simbols.

lunes, 26 de enero de 2015

Mastery 01

I did my first program. Yay me!!!

its a simple "Hello world" program.

it uses the pyhton premade fuction print.

the way you use it is
type the word print, and following it you write what you want to be displayed (a variable, a return value, a string, etc.) in between parenthesis. if its a string it must be sadwiched in between qutations marks inside the parenthesis,

example:
print("Hello Wolrd")

or:
a= 5 + 2
print(a)



jueves, 22 de enero de 2015

WSQ #02: Flipped classroom, the dawn of the double letters.

This post is all about flipped class:

flipped class allows for a more work efficient enviroment that allows for a ctivity centric class room and you wont spent valuable time on lectures.

this cute video sums it all up in an ellegant manner.


lunes, 19 de enero de 2015

WSQ1

#wsq1.

I downloaded python on my laptop, I want to thank Oscar who posted a video to his blog that helped me with the process.

Here is a screenshot of all the downloaded files to prove it. FIN

I signed Page 1

#wsq00

Hey Ken,

I signed page one, see:

signature. 


jueves, 15 de enero de 2015

Mastery03

hey Ken, this my post for #mastery03 :

twitter: @merino996
Github: EduardoMerino (its signed with my itesm mail, so there's that)

ok- bye

lunes, 12 de enero de 2015

What´s programming all about?

I don't know. But I guess you type really fast into a computer and you think really hard about it and it will show up in your iPad. I´m funny, right? ha. To be serious I do know some things but its very basic, I wish to get better as I progress in this blog. FIN (I don't know how to end this post).