Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- value_one = 10
- value_two = 20
- result = value_one + value_two
- print "The result is equal to ", result
- def AddTwoNumbers(first_value, second_value): # function definition called AddTwoNumbers and it takes 2 parameters - first_value and second value
- result = 0 #I declare a variable to hold onto the result of adding the 2 numbers
- result = first_value + second_value #the 2 numbers that I passed as parameters are added together and the value is assigned to the variable result.
- return result #finally I return the result to the where I called the function
- myResult = AddTwoNumbers(10,20) # #This will call the function defined above and pass the number 10 and store it in first_value, and store 20 in second_value
- print "The result = ", myResult #This will print the result
- #Now I can call that function over and over again - functions make code reusable if we want to do some work multiple times
- myResult = AddTwoNumbers(5, 6)
- print "The result = ", myResult
- myResult = AddTwoNumbers(15,98)
- print "The result = ", myResult
- myResult = AddTwoNumbers(6, 9)
- print "The result = ", myResult
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement