Skip to content

Instantly share code, notes, and snippets.

@jamiebullock
Created February 15, 2020 18:37
Show Gist options
  • Save jamiebullock/f60b52fdd45e4a361ab71944b4f27733 to your computer and use it in GitHub Desktop.
Save jamiebullock/f60b52fdd45e4a361ab71944b4f27733 to your computer and use it in GitHub Desktop.
Calculator with conditional branching
num1 = input("First Number:\n")
operator = input("Operator (+, -, *, /):\n")
num2 = input("Second Number:\n")
num1 = float(num1)
num2 = float(num2)
out = None
if operator == "+":
out = num1 + num2
elif operator == "-":
out = num1 - num2
elif operator == "*":
out = num1 * num2
elif operator == "/":
out = num1 / num2
print("Answer: " + str(out))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment