Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def addition():
- return x + y
- def subtraction():
- return x - y
- def multiplication():
- return x * y
- def division():
- return x / y
- print("""Welcome to Gaspavar's calculator!""")
- while True:
- operation = str(input("Choose an operation: "))
- if operation.lower() != "addition" and operation.lower() != "subtraction" and operation.lower() != "multiplication" and operation.lower() != "division":
- print("Invalid value, please try again.")
- else:
- break
- while True:
- try:
- x = float(input("Choose your first number: "))
- y = float(input("Choose your second number "))
- except ValueError:
- print("You can enter only numbers, please try again")
- else:
- break
- if operation.lower() == "addition":
- print("Your result is " + str(addition()))
- elif operation.lower() == "subtraction":
- print("Your result is " + str(subtraction()))
- elif operation.lower() == "multiplication":
- print("Your result is " + str(multiplication()))
- elif operation.lower() == "division":
- print("Your result is " + str(division()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement