Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. # - - coding: utf- 8 - -
  2. '''
  3. # Funksjonen er called med 2 argumenter a og b
  4. Printer ut hva funksjonen gjør "i dette tilfelle ADDING +"
  5.  
  6. '''
  7. def add(a, b):
  8. print "Adding %d + %d" % (a, b)
  9. return a + b
  10.  
  11. def subtract(a, b):
  12. print "Subtracting %d - %d" % (a, b)
  13. return a - b
  14.  
  15. def multiply(a, b):
  16. print "multiplying %d * %d" % (a, b)
  17. return a * b
  18.  
  19. def divide(a,b):
  20. print "Dividing %d / %d" % (a, b)
  21. return a / b
  22.  
  23. print "Let's do some math with just functions!"
  24.  
  25. age = add(30, 5)
  26. height = subtract(78, 4)
  27. weight = multiply(90, 2)
  28. iq = divide(100, 2)
  29.  
  30. print "Age: %d, Height: %d, Weight: %d, IQ: %d" % (age, height, weight, iq)
  31.  
  32. print "Here is a puzzle."
  33. what = add(age, subtract(height, multiply(weight, divide(iq, 2))))
  34. print "That becomes: ", what, "can you do it by hand?"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement