Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # store all possible operators
- operators = ["+","-","*","/","**","//"]
- validNumber = False
- while not validNumber:
- try:
- num1 = float(input("enter the first number : "))
- validNumber = True
- except ValueError:
- print("invalid number")
- validOperator = False
- while not validOperator:
- try:
- operator = input("enter the operator \n(+ or - or * or / or ** = Power or // ) : ")
- if operator in operators:
- validOperator = True
- else:
- print("invalid operator")
- except ValueError:
- print("invalid operator")
- validNumber = False
- while not validNumber:
- try:
- num2 = float(input("enter the second number : "))
- validNumber = True
- except ValueError:
- print("invalid number")
- print()
- if operator in operators:
- print(f"{int(num1)} {operator} {int(num2)} = {eval(str(num1)+operator+str(num2))}")
- else:
- print("invalid operator")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement