calc.py 697 Bytes
Newer Older
1
2
3

parsed = False

4
operand1 = input("First operand: ")
5
6
7
8
9
10
11
while not parsed:
    try:
        operand1 = int(operand1)
        parsed = True
    except ValueError:
        print(operand1 + " is not a number!")
        operand1 = input("First operand: ")
12

13
operator = input("Operator: ")
14

15
16
17
18
19
20
21
22
operand2 = input("Second operand: ")
while not parsed:
    try:
        operand2 = int(operand2)
        parsed = True
    except ValueError:
        print(operand2 + " is not a number!")
        operand2 = input("Second operand: ")
Gilles Coremans's avatar
Gilles Coremans committed
23

Gilles Coremans's avatar
Gilles Coremans committed
24
print("Your result is:")
Gilles Coremans's avatar
Gilles Coremans committed
25
if operator == "+":
Gilles Coremans's avatar
Gilles Coremans committed
26
    print(operand1 * operand2)
Gilles Coremans's avatar
Gilles Coremans committed
27
28
elif operator == "-":
    print(operand1 - operand2)
Gilles Coremans's avatar
Gilles Coremans committed
29
30
else:
    print("Unsupported operation " + operator)