Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #operations
- def a(x,y):
- return x + y
- def m(x,y):
- return x * y
- def s(x,y):
- return x - y
- def d(x,y):
- try:
- return x / y
- except ZeroDivisionError:
- print ("Unable to divide by 0. Try another number.")
- while True:
- try:
- x = float(input("Enter a number-->\n"))
- y = float(input("Enter another number-->\n"))
- except (ValueError, NameError):
- print ("Invalid input. Please try again.")
- continue
- try:
- o = input("Select an Operation--> (+) (*) (-) (/)\n")
- except (ValueError, NameError):
- print ("Invalid Operation. Please try again. (+ or * or - or /)")
- continue
- if o == "+":
- ans = a(x,y)
- elif o == "*":
- ans = m(x,y)
- elif o == "-":
- ans = s(x,y)
- elif o == "/":
- ans = d(x,y)
- if y != 0:
- print ("Your answer is:")
- print ("x" , o , "y" , "=" , ans , sep=" ")
- else:
- continue
- while True:
- restart = input ("Run again? (y / n)")
- if restart == 'y':
- break
- elif restart != "n":
- print ("Invalid input. Type (y / n)")
- continue
- else:
- print ("Thanks for using my calculator!")
- quit()
- else:
- print("An unexpected error has occured. Terminating...")
- quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement