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:
#GILBERTO ROGEL GARCÍA A01630171
def osuma (num1,num2):
suma=num1+num2 #this 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))
]]>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:
#GILBERTO ROGEL GARCÍA A01630171
def osuma (num1,num2):
suma=num1+num2 #this 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))
]]>Repost for the #WSQ06 because the other post is bugged D:
Useful links: http:/
How to use a while function in python: http:/
Code:
#Gilberto Rogel García a01630171
import random
value= random.randint(1,100)
tries=0
num= int(input(“Guess a number from 1 to 100:”))
while num != value:
if num>value :
print (num, “is too high”)
num= int(input(“Try again:”))
tries=tries+1
elif num<value :
print (num, “is too low”)
num= int(input(“Try again:”))
tries= tries+1
tries= tries +1
print(“Congratulations!, The right number is”,value)
print(“It took you” ,tries, “tries to win”)
]]>I had already done something like this in Introduccion ala computación class in c# so it wasnt a problem for me to do it again in python…i think python is easier because i dont have to use these things { }
Here’s my code
#Gilberto Rogel García A01630171
print(“We will calculate the sum of integers in the range you provide”)
result= 0
num1=int(input(“Please give us the lower bound:”))
num2=int(input(“Please give us the upper bound:”))
while num1>num2:
print (“User input error, please give us the numbers again”)
num1=int(input(“Please give us the lower bound:”))
num2=int(input(“Please give us the upper bound:”))
while num1<num2 :
result=result + num1
num1=num1+1
result=result+num1
print (“The sum from your lower bound to your upper bound is”,result)
]]>#333333; line-height: 1.5em !important;”>I learned how to use the while function in python thanks to this WSQ. Its easier to do a “while” than a lot of “ifs”, thats why i made my code with a single while function.
#333333; line-height: 1.5em !important;”>I used this links that showed me how to get a random number and how to use the while function in python.
#333333; line-height: 1.5em !important;”>#4c93cb; text-decoration: none;” href=”http://stackoverflow.com/questions/5555712/generate-a-random-number”>http:/
#333333; line-height: 1.5em !important;”>#4c93cb; text-decoration: none;” href=”http://www.tutorialspoint.com/python/python_loops.htm”>http:/
#333333; line-height: 1.5em !important;”>Here’s my code:
#333333; line-height: 1.5em !important;”>#8cbf99; text-decoration: none; font-family: ‘Helvetica Neue’, Helvetica, Arial, sans-serif; padding: 3px; font-size: 1em; background-repeat: repeat-x;” href=”http://gilrg18.withknown.com/tag/Gilberto” rel=”tag”>#Gilberto Rogel García a01630171
#333333; line-height: 1.5em !important;”>import random
#333333; line-height: 1.5em !important;”>value= random.randint(1,100)
#333333; line-height: 1.5em !important;”>tries=0
#333333; line-height: 1.5em !important;”>num= int(input(“Guess a number from 1 to 100:”))
#333333; line-height: 1.5em !important;”>while num != value: ###the while funtion starts here, i put “!=” so when the number is different from value the while function will take place.
#333333; line-height: 1.5em !important;”>if num>value :
#333333; line-height: 1.5em !important;”>print (num, “is too high”)
#333333; line-height: 1.5em !important;”>num= int(input(“Try again:”))
#333333; line-height: 1.5em !important;”>tries=tries+1
#333333; line-height: 1.5em !important;”>elif num<value :
#333333; line-height: 1.5em !important;”>print (num, “is too low”)
#333333; line-height: 1.5em !important;”>num= int(input(“Try again:”))
#333333; line-height: 1.5em !important;”>tries= tries+1
#333333; line-height: 1.5em !important;”>tries= tries +1 ###here is where the while function ends, when the number is equal to value.
#333333; line-height: 1.5em !important;”>print(“Congratulations!, The right number is”,value)
#333333; line-height: 1.5em !important;”>print(“It took you” ,tries, “tries to win”)
#333333; line-height: 1.5em !important;”>#8cbf99; text-decoration: none; font-family: ‘Helvetica Neue’, Helvetica, Arial, sans-serif; padding: 3px; font-size: 1em; background-repeat: repeat-x;” href=”http://gilrg18.withknown.com/tag/TC1014″ rel=”tag”>#TC1014 #8cbf99; text-decoration: none; font-family: ‘Helvetica Neue’, Helvetica, Arial, sans-serif; padding: 3px; font-size: 1em; background-repeat: repeat-x;” href=”http://gilrg18.withknown.com/tag/WSQ06″ rel=”tag”>#WSQ06
]]>#333333; line-height: 1.5em !important;”>I learned how to use the while function in python thanks to this WSQ. Its easier to do a “while” than a lot of “ifs”, thats why i made my code with a single while function.
#333333; line-height: 1.5em !important;”>I used this links that showed me how to get a random number and how to use the while function in python.
#333333; line-height: 1.5em !important;”>#4c93cb; text-decoration: none;” href=”http://stackoverflow.com/questions/5555712/generate-a-random-number”>http:/
#333333; line-height: 1.5em !important;”>#4c93cb; text-decoration: none;” href=”http://www.tutorialspoint.com/python/python_loops.htm”>http:/
#333333; line-height: 1.5em !important;”>Here’s my code:
#333333; line-height: 1.5em !important;”>#8cbf99; text-decoration: none; font-family: ‘Helvetica Neue’, Helvetica, Arial, sans-serif; padding: 3px; font-size: 1em; background-repeat: repeat-x;” href=”http://gilrg18.withknown.com/tag/Gilberto” rel=”tag”>#Gilberto Rogel García a01630171
#333333; line-height: 1.5em !important;”>import random
#333333; line-height: 1.5em !important;”>value= random.randint(1,100)
#333333; line-height: 1.5em !important;”>tries=0
#333333; line-height: 1.5em !important;”>num= int(input(“Guess a number from 1 to 100:”))
#333333; line-height: 1.5em !important;”>while num != value: ###the while funtion starts here, i put “!=” so when the number is different from value the while function will take place.
#333333; line-height: 1.5em !important;”>if num>value :
#333333; line-height: 1.5em !important;”>print (num, “is too high”)
#333333; line-height: 1.5em !important;”>num= int(input(“Try again:”))
#333333; line-height: 1.5em !important;”>tries=tries+1
#333333; line-height: 1.5em !important;”>elif num<value :
#333333; line-height: 1.5em !important;”>print (num, “is too low”)
#333333; line-height: 1.5em !important;”>num= int(input(“Try again:”))
#333333; line-height: 1.5em !important;”>tries= tries+1
#333333; line-height: 1.5em !important;”>tries= tries +1 ###here is where the while function ends, when the number is equal to value.
#333333; line-height: 1.5em !important;”>print(“Congratulations!, The right number is”,value)
#333333; line-height: 1.5em !important;”>print(“It took you” ,tries, “tries to win”)
#333333; line-height: 1.5em !important;”>#8cbf99; text-decoration: none; font-family: ‘Helvetica Neue’, Helvetica, Arial, sans-serif; padding: 3px; font-size: 1em; background-repeat: repeat-x;” href=”http://gilrg18.withknown.com/tag/TC1014″ rel=”tag”>#TC1014 #8cbf99; text-decoration: none; font-family: ‘Helvetica Neue’, Helvetica, Arial, sans-serif; padding: 3px; font-size: 1em; background-repeat: repeat-x;” href=”http://gilrg18.withknown.com/tag/WSQ06″ rel=”tag”>#WSQ06
]]>