Advertisement
Morbo

function testing

May 2nd, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. def add(a,b):
  2.     print('adding %d + %d' % (a,b))
  3.     return a + b
  4.  
  5. def subtract(a,b):
  6.     print('subtracting %d - %d' % (a,b))
  7.     return a - b
  8.  
  9. def multiply(a,b):
  10.     print('multiplying %d * %d' % (a,b))
  11.     return a * b
  12.  
  13. def divide(a,b):
  14.     print('dividing %d / %d' % (a,b))
  15.     return a / b
  16.  
  17. print('Let\'s do some math with just functions!\n')
  18.  
  19. age = add(30,5)
  20. height = subtract(78,4)
  21. weight = multiply(90,2)
  22. iq = divide(100,2)
  23.  
  24. print('Age: %d, Height: %d, Weight: %d, IQ: %d\n' % (age,height,weight,iq))
  25. print('~' * 80)
  26. #a puzzle for extra credit
  27. print('Here is a puzzle\n')
  28.  
  29.  
  30. what = add(age,subtract(height,multiply(weight,divide(iq,2))))
  31.  
  32. print('That becomes: ', what, 'Can you do it by hand?')
  33. x = iq
  34. w = weight
  35. s = height
  36. f = age
  37. print(s-x/2*w+f)
  38. print((s-((x/2)*w))+f)
  39. print(-(((int(x) / 2) * int(w)) - int(s)) + int(f) )
  40. #print('(((iq/2)*weight)-height)+add')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement