I also learned a lot from this video.
Mostrando entradas con la etiqueta masteries. Mostrar todas las entradas
Mostrando entradas con la etiqueta masteries. Mostrar todas las entradas
lunes, 4 de mayo de 2015
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.

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:
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: palindromes, standard 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.
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?.
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=0while (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=
String can also be multiplied as seen in this program.
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.
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.
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.
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:
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.
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:
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):
will become:
and the variable the_sum will receve the return value of:
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.
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 ansso 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 answill become:
make_sum(2,5):
ans=2+5
return ansand the variable the_sum will receve the return value of:
make_sum(2,5):
ans=2+5
return answich 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 ansthis program shown here uses personally made fuctions:
you can copy and paste the code from this link to try it on your own.
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.
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.
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
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:
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.
Suscribirse a:
Entradas (Atom)








