Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,34 @@ def div(a, b):

while (True):
# get input values
a = raw_input("Enter the first argument: ")
op = raw_input("Enter the operation: ")
b = raw_input("Enter the second argument: ")
a = input("Enter the first argument: ")
op = input("Enter the operation: ")
b = input("Enter the second argument: ")
try:
a = int(a)
b = int(b)
except ValueError:
print "Invalid number argument..."
print("Invalid number argument...")
op = None

# decide function
if (op != None):
if (op == "+"):
print "Sum: ", add(a, b)
print("Sum: ", add(a, b))
elif (op == "-"):
print "Difference: ", sub(a, b)
print("Difference: ", sub(a, b))
elif (op == "*"):
print "Product: ", mult(a, b)
print("Product: ", mult(a, b))
elif (op == "/"):
print "Quotient: ", div(a, b)
print("Quotient: ", div(a, b))
elif (op == "^"):
print("Power: ", pow(a, b))
elif (op == "%"):
print("Modulus: ", a%b)
else:
print "Invalid operation..."
print("Invalid operation...")

q = raw_input("Quit? [y/n] ")
q = input("Quit? [y/n] ")
if (q == "y" or q == "Y"):
break

Expand Down