Calculator #128623
Unanswered
RajanMistry12
asked this question in
Programming Help
Calculator
#128623
Replies: 8 comments 2 replies
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
|
Beta Was this translation helpful? Give feedback.
0 replies
This comment was marked as spam.
This comment was marked as spam.
-
python code def calculator(operand1, operator, operand2):
try:
operand1 = float(operand1)
operand2 = float(operand2)
except ValueError:
return "Error: Invalid number format."
if operator == '+':
return operand1 + operand2
elif operator == '-':
return operand1 - operand2
elif operator == '*':
return operand1 * operand2
elif operator == '/':
if operand2 == 0:
return "Error: Division by zero is not allowed."
return operand1 / operand2
elif operator == '%':
return (operand1 * operand2) / 100
else:
return "Error: Invalid operator."
# Example usage
operand1 = input("Enter the first number: ")
operator = input("Enter an operator (+, -, *, /, %): ")
operand2 = input("Enter the second number: ")
result = calculator(operand1, operator, operand2)
print("Result:", result) |
Beta Was this translation helpful? Give feedback.
2 replies
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Select Topic Area
Question
Body
I want prepare a simple calculator which is following my Tearm and conditions
Beta Was this translation helpful? Give feedback.
All reactions