Advertisement
182days

Calculator (Div0 & Float)

May 10th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. #calculator using main math functions, float & integer capable, divide by zero check and working out shown.
  2.  
  3. #integer functions
  4. def addi():
  5.     num1=int(input("enter first number"))
  6.     num2=int(input("enter first number"))
  7.     ans = (num1) + (num2)
  8.     print(num1, "Plus", num2, "=", ans)
  9. def subtracti():
  10.     num1=int(input("enter first number"))
  11.     num2=int(input("enter first number"))
  12.     ans = (num1) - (num2)
  13.     print(num1, "Minus", num2, "=", ans)
  14. def dividei():
  15.     num1=int(input("enter first number"))
  16.     num2=int(input("enter first number"))
  17.     if num2 == 0:
  18.         print("Math Error")
  19.     else:
  20.         ans = (num1) / (num2)
  21.         print(num1, "Divided by", num2, "=", ans)
  22. def multiplyi():
  23.     num1=int(input("enter first number"))
  24.     num2=int(input("enter first number"))
  25.     ans = (num1) * (num2)
  26.     print(num1, "Multiplied by", num2, "=", ans)
  27.  
  28. #floating functions
  29. def addf():
  30.     num1=float(input("enter first number"))
  31.     num2=float(input("enter first number"))
  32.     ans = (num1) + (num2)
  33.     print(num1, "Plus", num2, "=", ans)
  34. def subtractf():
  35.     num1=float(input("enter first number"))
  36.     num2=float(input("enter first number"))
  37.     ans = (num1) - (num2)
  38.     print(num1, "Minus", num2, "=", ans)
  39. def dividef():
  40.     num1=float(input("enter first number"))
  41.     num2=float(input("enter first number"))
  42.     if num2 == 0:
  43.         print("Math Error")
  44.     else:
  45.         ans = (num1) / (num2)
  46.         print(num1, "Divided by", num2, "=", ans)
  47. def multiplyf():
  48.     num1=float(input("enter first number"))
  49.     num2=float(input("enter first number"))
  50.     ans = (num1) * (num2)
  51.     print(num1, "Multiplied by", num2, "=", ans)
  52.  
  53. while True:
  54.     print("Elenas Calculator v1.0")
  55.     choice=input("""ai = add integer
  56. af = add float
  57. si = subtract integer
  58. sf = subtract float
  59. di = divide integer
  60. df = divide float
  61. mi = multiply integer
  62. mf = multiply float""")
  63.     if choice =="ai":
  64.         addi()
  65.     if choice == "af":
  66.         addf()
  67.     if choice == "si":
  68.         subtracti()
  69.     if choice == "sf":
  70.         subtractf()
  71.     if choice == "di":
  72.         dividei()
  73.     if choice == "df":
  74.         dividef()
  75.     if choice == "mi":
  76.         multiplyi()
  77.     if choice == "mf":
  78.         multiplyf()
  79.     else:
  80.         print("Wrong selection!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement