Skip to content

Commit 228e2aa

Browse files
committed
ADDED: Validator to validate the operations entered for calculations
1 parent a5472f8 commit 228e2aa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Simple Calculator.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
operation = ""
44
num2 = ""
55
num1 = input("Hello, What is your First Number?\n")
6-
operation = input("Operation?\n")
6+
operation = input("Operation (+, -, *, /)?\n")
77
num2 = input("Your Second Number?\n")
88

99
floatnum1 = float(num1)
@@ -17,5 +17,7 @@
1717
output=floatnum1*floatnum2
1818
if operation == "/":
1919
output=floatnum1/floatnum2
20-
21-
print("Your Answer: "+str(output))
20+
if operation == "+" or operation == "-" or operation == "/" or operation == "*":
21+
print("Your Answer: "+str(output))
22+
else:
23+
print("Your operation is invalid, please try again")

0 commit comments

Comments
 (0)