Tag Archives: #this

#mastery15 Use of the conditional “if”

What the “if” does is that if a condition is fulfiled it will do what it is inside of it.

An example of this is

num=1+1

if (num>3):

print (“Hello”) must be idented so it can be part of the if

This program wont print anything because the condition num>3 is not fulfiled , in order for it to print something it must be num<3 or num=2 because num equals 2

num=1+1

if (num<3):

print(“Hello”) must be idented so it can be part of the if

This program will show the user:

Hello the condition is now fulfiled (2<3) 

 

#mastery13 Importing and using Python modules

An example of this can be found on my WSQ06, here’s the part of the code where i imported a module:

import random imported the module random that in this case it produces a random intenger from a certain parameter 

value= random.randint(1,100) this line does is that the variable value will become a random integer (random.randint) from 1 to 100 (1,100)

print(value)

This program will show a random value from 1 to 100.

Another example is:

import math import the module math which has lots of functions that can be found here https://docs.python.org/2/library/math.html

pi=math.pi will take math.pi’s value which  is equivalent to 3.1416…

print (pi)

This program will show:

3.141592653589793

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

 

#TC1014 #WSQ08 On to functions

For this WSQ i had to read chapter 3 of the book ”  “Think Python, How to Think Like a Computer Scientist” which explained how to make functions.

Here’s my code:

ROGEL GARCÍA A01630171

def osuma (num1,num2):

suma=num1+num2 line must be idented in order for the function to work properly.

return suma  #this line must be idented in order for the function to work properly.

 

def oresta (num1,num2):

resta=num1-num2 #this line must be idented in order for the function to work properly.

return resta  #this line must be idented in order for the function to work properly.

 

def omulti (num1,num2):

multi=num1*num2  #this line must be idented in order for the function to work properly.

return multi  #this line must be idented in order for the function to work properly.

 

def odiv (num1,num2):

div=num1/num2

return div

 

def orem(num1,num2):

rem= num1%num2  #this line must be idented in order for the function to work properly.

return rem  #this line must be idented in order for the function to work properly.

 

 

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

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

 

su=osuma(num1,num2)

res=oresta(num1,num2)

mult=omulti(num1,num2)

di=odiv(num1,num2)

re=orem(num1,num2)

 

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

#TC1014 #WSQ08 On to functions

For this WSQ i had to read chapter 3 of the book ”  “Think Python, How to Think Like a Computer Scientist” which explained how to make functions.

Here’s my code:

ROGEL GARCÍA A01630171

def osuma (num1,num2):

suma=num1+num2 line must be idented in order for the function to work properly.

return suma  #this line must be idented in order for the function to work properly.

 

def oresta (num1,num2):

resta=num1-num2 #this line must be idented in order for the function to work properly.

return resta  #this line must be idented in order for the function to work properly.

 

def omulti (num1,num2):

multi=num1*num2  #this line must be idented in order for the function to work properly.

return multi  #this line must be idented in order for the function to work properly.

 

def odiv (num1,num2):

div=num1/num2

return div

 

def orem(num1,num2):

rem= num1%num2  #this line must be idented in order for the function to work properly.

return rem  #this line must be idented in order for the function to work properly.

 

 

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

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

 

su=osuma(num1,num2)

res=oresta(num1,num2)

mult=omulti(num1,num2)

di=odiv(num1,num2)

re=orem(num1,num2)

 

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

#TC1014 #WSQ03

2 min read

Here’s my code for the #WSQ03, i used these links as a reference to help me deal with this task: http://stackoverflow.com/questions/17651384/python-remove-division-decimal 

http://stackoverflow.com/questions/5584586/find-the-division-remainder-of-a-number

 I have put some comments in the code to explain what each line does.

num1 = int(input(“Give me a number: “)) #Asks the user for a number

num2 = int(input (“Give me another number: “)) #Asks the user for another number

suma = num1+num2 #this is the variable for the sum of two numbers

resta= num1-num2  #this is the variable for the difference of two numbers

multi= num1*num2  #this ios the variable for the product of two numbers

div=num1/num2 #this is the variable for the division of two numbers

rem= num1%num2 #this is the variable for the remainder of the division of two numbers

print (“The sum of your numbers is”, suma) #Shows the user the result of the sum

print (“The difference of your numbers is”, resta) #Shows the user the result of the difference

print (“The product of your numbers is”, multi) #Shows the user the result of the product

print (“The division of your numbers is”, int(div)) #Shows the user the result of the division

print(“The remainder of the division of your numbers is”, int(rem)) #Shows the user the remainder of the division

I could have printed every result in one print function but i think it looks better this way. 🙂 #TC1014 #WSQ03