Guest User

Untitled

a guest
Jan 24th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. # -*- coding: iso-8859-1 -*-
  2.  
  3.  
  4. def add(a, b):
  5. c = a + b
  6. return c
  7.  
  8. def subtract(a, b):
  9. c = a - b
  10. return c
  11.  
  12. def multiply(a, b):
  13. c = a * b
  14. return c
  15.  
  16. def divide(a, b):
  17. if b != 0:
  18. c = a / b
  19. return c
  20. else:
  21. print "Cannot divide by zero."
  22. return None
  23.  
  24.  
  25. def main():
  26. loop = True
  27. while loop:
  28. print "(a)dd, (s)ubtract, (m)ultiply, (d)ivide, (q)uit"
  29. operation = raw_input("Give an operation: ")
  30.  
  31. if operation == "q":
  32. loop = False
  33.  
  34. elif operation in ("a", "s", "m", "d"):
  35. first = float(raw_input("First number: "))
  36. second = float(raw_input("Second number: "))
  37.  
  38.  
  39. if operation == "a":
  40. tulos = add(first, second)
  41. print "%.1f" %(tulos)
  42. continue
  43.  
  44. elif operation == "s":
  45. tulos = subtract(first, second)
  46. print "%.1f" %(tulos)
  47. continue
  48.  
  49. elif operation == "m":
  50. tulos = multiply(first, second)
  51. print "%.1f" %(tulos)
  52. continue
  53.  
  54. elif operation == "d":
  55. tulos = divide(first, second)
  56. if tulos == (None):
  57. continue
  58. else:
  59. print "%.1f" %(tulos)
  60. continue
  61.  
  62.  
  63. else:
  64. print "WHAT ARE YOU DOING?"
  65. continue
  66.  
  67.  
  68. if __name__ == '__main__':
  69. main()
Add Comment
Please, Sign In to add comment