calc.py 503 Bytes
Newer Older
1
operand1 = input("First operand: ")
Gilles Coremans's avatar
Gilles Coremans committed
2
operator = input("Operator: ")
3
4
5
6
7
8
9
10
11
12
13
14
15
operand2 = input("Second operand: ")

try:
    operand1 = int(operand1)
except ValueError:
    print(operand1 + " is not a number!")
    exit(1)

try:
    operand2 = int(operand1)
except ValueError:
    print(operand1 + " is not a number!")
    exit(1)
Gilles Coremans's avatar
Gilles Coremans committed
16

Gilles Coremans's avatar
Gilles Coremans committed
17
print("Your result is:")
Gilles Coremans's avatar
Gilles Coremans committed
18
19
if operator == "+":
    print(operand1 + operand2)
Gilles Coremans's avatar
Gilles Coremans committed
20
21
elif operator == "-":
    print(operand1 - operand2)
Gilles Coremans's avatar
Gilles Coremans committed
22
23
else:
    print("Unsupported operation " + operator)