Skip to content

Instantly share code, notes, and snippets.

@RaMSFT
Created October 20, 2022 07:09
Show Gist options
  • Save RaMSFT/3111090234d26bcee15144b399fd05a0 to your computer and use it in GitHub Desktop.
Save RaMSFT/3111090234d26bcee15144b399fd05a0 to your computer and use it in GitHub Desktop.
def calculate_with_op(num1, num2, op):
equation = f"{num1} {op} {num2}"
result = eval(equation)
return f"equation: {equation} results: {result}"
print(calculate_with_op(4, 9, "+"))
print(calculate_with_op(12, 5, "-"))
print(calculate_with_op(6, 3, "*"))
print(calculate_with_op(25, 5, "//"))
print(calculate_with_op(14, 3, "%"))
print(calculate_with_op(7, 2, "/"))
print(calculate_with_op(4, 9, "**"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment