Advertisement
Guest User

Gaspavar's calculator

a guest
Aug 22nd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. def addition():
  2. return x + y
  3.  
  4.  
  5. def subtraction():
  6. return x - y
  7.  
  8.  
  9. def multiplication():
  10. return x * y
  11.  
  12.  
  13. def division():
  14. return x / y
  15.  
  16.  
  17. print("""Welcome to Gaspavar's calculator!""")
  18. while True:
  19. operation = str(input("Choose an operation: "))
  20. if operation.lower() != "addition" and operation.lower() != "subtraction" and operation.lower() != "multiplication" and operation.lower() != "division":
  21. print("Invalid value, please try again.")
  22. else:
  23. break
  24. while True:
  25. try:
  26. x = float(input("Choose your first number: "))
  27. y = float(input("Choose your second number "))
  28. except ValueError:
  29. print("You can enter only numbers, please try again")
  30. else:
  31. break
  32.  
  33. if operation.lower() == "addition":
  34. print("Your result is " + str(addition()))
  35. elif operation.lower() == "subtraction":
  36. print("Your result is " + str(subtraction()))
  37. elif operation.lower() == "multiplication":
  38. print("Your result is " + str(multiplication()))
  39. elif operation.lower() == "division":
  40. print("Your result is " + str(division()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement