Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152
‘#mastery11’ Articles at TC101 Fall 2015, Page 4
Introduction to Programming Python and C++

Tag Archives: #mastery11

#Masteries 11 & 12

Here is the video for my 11 and 12 masteries
Create C++ functions and Call C++ functions

Masteries 11 & 12

Calling Python function
Creating Python functions

Masteries 11 & 12

Calling Python function
Creating Python functions

Masteries 11 and 12 – Calling and creating functions

Functions in Python are very easy to use, they do specific actions with the value you call them. The function substitute a value into a block of code and the returns the calculation (or sometimes they do nothing). For example, you have probably used before the print function:

Print(“Hello world”)
This funtion is a built-in-function that takes an integer or a string (or a combination of them) and prints them for the user. There are a lot of built-in-funtions but we are not going to ge into all of them, the way to recognize a function is to see a word and then a value(or values) between parenthesis.
Name_function(value)
Name_function(value,value1,value2)

Calling a function

In order to work all functions need to be called. You can just write the name of the function with some values inside but that is just going to calculate whatever the function do without responding to the user. If you want to show the calculation to the user you can include the function in a print function or asign the value of the calculation to a variable:
superpower(2,3) #Gives you the value of x raised to the y
nothing happens
print (superpower(2,3))
8
value = superpower(2,3)
print (value)
Keep in mind that if you want that the function takes a value and return it (adquire the value) you need to put the word return inside the function. If you dont do this the function will do nothing and you wont b able to use it for more calculations. 

Creating a function

Now that you know how to call a function you can create one. The stepts are really simple. Fisrt lets see the body of a function:
def function_sum(x,y,z):
     return x+y+z
As you can see to create a function we need to tell Python that we want to make one so we write def, this way Python will know that you are creating a function and not calling it. The next step is to write the name, you can use whatever name you want but keep in mind that if you are in a big project you are going to use a lot of functions so use names easy to remember. I recommend you to name the function with something related to it like:
def root_square(x) #It calculates the root square of a number
def pyramid(x) #It prints a pyramid made of strings
def fibonacci(x) #It prints the value of n in the fibonacci sequence
The next ting to do is to write the parameters that you want the function to take, it can be anything as long as you use them inside the function. It works as a variable but they are not a variable, it just sustitute the values inside the function. Look at the first example and you can see that I used 3 parameters (x, y and z) and later on I used them inside the function to retunr the value of a sum of the 3 parameters. Lets see some examples of the function working:
print (function_sum(1,2,3))
6
print (function_sum(10,4,16))
30
Remember to use the return so that we can use it as the value of the calculation
function_sum(1,2,3) + 10  #6 + 10
nothing 
Remember that we need to print it or asing it to a value. Otherwise the calculation will be useless.
print (funtion_sum(1,2,3) + 10)
16

Notes

-While creating the function remeber to use the : at the end and then put the code inside the function with identation
-Remember that most of the time the function needs the return
-You can use as many parameters as you want
-While calling the function remember to give the value some use, print it or asign it to a variable


Masteries 11. & 12.

Description: Calling C++ functions and creating C++ functions. Just like peas in a pod, these two masteries go together. And will forever remain so. Video for both masteries here.

Masteries 11 & 12

In this short video I explain how to create and call a simple function to print it with a “cout<<“.

Masteries 11. & 12.

Description: Calling C++ functions and creating C++ functions. Just like peas in a pod, these two masteries go together. And will forever remain so. Video for both masteries here.

#Mastery11

Calling C++ functions

#Mastery11 – Calling C++ functions

Hello, this is which shows how to call functions in c++. Using many functions in a program, lets you divide the work on the code in parts this has a pro because if you mess up during the coding of the function, the error would come up easier.

 

It is possible to call one function form another function (result). For example, if you are calling a function named time () inside of main ()

 

Int main ()

{time (); // This is calling the function time inside of main.

return 0;

}

 

Its is also possible to declare a function before calling it. For example:

 

Void time ()

 

Int main () {

 

            Void ();

}

     Return 0;

}

 

Remember to be careful with the order in coding, because every command has its specific place to be working. Sometimes, the compiler can do its work and display no errors, but don´t be completely sure, because sometimes the compiler may not display any message, but the error may me in the order of the commands.

 

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

WATCH MY VIDEO  https://youtu.be/9UuwAnWXiig

What should you work on?

Week #12 and more partial exams for you.

For this week's readings:
C++ (TC1017) should either be looking at support for your project, ImageMagick C++ libraries are a good start.
Python (TC1014) should be finishing chapter 11 (Dictionaries).