Jayteepix

Add-Sub-Mult-Div

Oct 19th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #Calculator Bot
  2. #I can Add, Subtract, Multiply and Divide two numbers
  3. print("Would you like to Add or Subtract, Multiply or Divide two numbers?")
  4. operator = input("Enter 'A' for Add, 'S' for Subtract, 'M' for Multiply or 'D' for Divide > ")
  5. if operator == "A" or operator == "S" or operator == "M" or operator == "D" :
  6. input1 = input("Please enter your first number ")
  7. input2 = input("now enter your second number ")
  8. num1 = float(input1)
  9. num2 = float(input2)
  10. if operator == "A":
  11. print("Add two numbers")
  12. result = num1 + num2
  13. output = str(result)
  14. print("The sum of " + input1 + " and " + input2 + " is " + output)
  15.  
  16. elif operator == "S":
  17. print("Subtract two numbers")
  18. result = num1 - num2
  19. output = str(result)
  20. print("The subtraction of " + input1 + " and " + input2 + " is " + output)
  21.  
  22. elif operator == "M":
  23. print("Multiply two numbers")
  24. result = num1 * num2
  25. output = str(result)
  26. print("The multiplication of " + input1 + " by " + input2 + " is " + output)
  27.  
  28. elif operator == "D":
  29. print("Divide two numbers")
  30. if num2 == 0:
  31. print("Can't divide by Zero sorry")
  32. else:
  33. result = num1 / num2
  34. output = str(result)
  35. print("The division of " + input1 + " by " + input2 + " is " + output)
  36. else:
  37. print("Try again and select 'A' / 'S' or 'M' / 'D' ")
  38. print("Bye")
Advertisement
Add Comment
Please, Sign In to add comment