-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-simple_calculator.py
More file actions
36 lines (28 loc) · 1.07 KB
/
3-simple_calculator.py
File metadata and controls
36 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ask user for calculation
operation = input("would you like to add/subtract/multiply/divide?").lower()
#ask for numbers to calculate
if operation =="subtract" or operation=="divide":
print("you chose{}.".format(operation))
print("please keep in mind that the order of your number matter")
num1 = input("what is the first number?")
num2 = input("what is the second number?")
#try/except for mathematical operation
try:
num1 , num2 = float(num1) , float(num2)
if operation == "add":
result = num1+num2
print("{} + {} = {}".format(num1 , num2, result))
elif operation == "subtract":
result = num1 - num2
print("{} - {} = {}".format(num1, num2,result))
elif operation == "multiply":
result = num1 * num2
print("{} * {} = {}".format(num1, num2, result))
elif operation == "divide":
result = num1/num2
print("{} / {} = {}".format(num1, num2,result))
else:
print("sorry , but '{}' is not an option".format(operation))
except :
print("Error: Improper numbers used. please try again")
#finall