Tag Archives: #function

#Mastery12

Functions are really useful when you want to structure and organize a program. Stating functions is really easy because you only need to write the type of value that the function will return and between “()” you declare the parameters.

Here you can see a picture of an example:

In this link you can find a pp that I did to explain how to create functions with detail: https://drive.google.com/file/d/0B-NM4ghaDXBvT0hGVmtHM3FDMms/view?usp=sharing

Also, here you can find my c++ code: https://drive.google.com/file/d/0B-NM4ghaDXBvVVI2Nmw3bUNVb0U/view?usp=sharing

Finally, in this link I found useful information to understand this, and I used that information to do my pp: http://www.cplusplus.com/doc/tutorial/functions/

 

#Mastery11

Using functions is useful to organize your code because these allows that your program has a structure divided by segments.

When you want to call a function is really simple because you only need to write the name of the function and the parameters.

Here you can see a program that calls functions:

I did a pp to explain how to call functions, I hope you find it useful, this is the link:

https://drive.google.com/file/d/0B-NM4ghaDXBvdFg3TnZCb2NnYXM/view?usp=sharing

Here you can find my c++ code:

https://drive.google.com/file/d/0B-NM4ghaDXBvREdHM1VwbjJqVEU/view?usp=sharing

#mastery11 Calling python functions

I used this link to help me do this mastery: https://docs.python.org/2/tutorial/controlflow.html#defining-functions

It is also useful to read chapter 3 of the book “Think Python, How to Think Like a Computer Scientist”, 

You can see an example of this in my . Here’s the code showing where i called the function that i defined:

def osuma (num1,num2): osuma

suma=num1+num2

return suma 

 

def oresta (num1,num2): oresta

resta=num1-num2

return resta

 

def omulti (num1,num2): omulti

multi=num1*num2

return multi

 

def odiv (num1,num2): odiv

div=num1/num2

return div

 

def orem(num1,num2): orem

rem= num1%num2

return rem

 

 

num1 = int(input(“Give me a number: “)) 

num2 = int(input (“Give me another number: “))

i called every function i defined in order for the variable to take the functions value

su=osuma(num1,num2) i called osuma function i defined in order for the variable to take the function’s value

res=oresta(num1,num2) i called oresta function i defined in order for the variable to take the function’s value

mult=omulti(num1,num2) i called omulti function i defined in order for the variable to take the function’s value

di=odiv(num1,num2) i called odiv function i defined in order for the variable to take the function’s value

re=orem(num1,num2) i called orem function i defined in order for the variable to take the function’s value

 

print (“The sum of your numbers is”, su) 

print (“The difference of your numbers is”, res) 

print (“The product of your numbers is”, mult) 

print (“The division of your numbers is”, int(di)) 

print(“The remainder of the division of your numbers is”, int(re)) 

 

#Mastery08

Python conventions (Zen of Python)

https://www.python.org/dev/peps/pep-0008/

Coding conventions are rules that were created by programers to make people’s life easier when reading a code. 

These conventions were created in order to have a better style when programming and that way, make the code easier to understand. 

Coding conventions include: