Tag Archives: #here

Use of comments in Python

 – Use of comments in Python                                                                          @PablO_CVi

Comments are tracks that the programer can add to the code, this won`t change anything in the program, this is just for helping the person that is going to use the code. For adding a comment in Python you just have to put a hashtag like this:   goes your comment. This is how you can add comments to your code in python. Here you can see that this does not modify the program.

Here is the code i used for this program: https://github.com/PablOCVi/Mastery/blob/master/Mastery07.py

#mastery12 Creating 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 the function that i created

def osuma (num1,num2): you have to define your function, in this case it’s osuma with num1 and num 2 as parameters

suma=num1+num2 is what the function does… this line must be idented so the function can work properly

return suma  #the return statement returns with a value from a function… this line must be idented so the function can work properly

 

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

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

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

 

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

 

#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)) 

 

Pick a number

#TC1014 #WSQ06 PICK A NUMBER