The problem is a calculator im trying to build and inside the define block is the result of my work but I cant print result outside of the def block because the result doesnt have value
I tried to import math and defined main(): and in the block I put every thing needed and outside the block I expected to give me the result but it gave me the error (UnboundLocalError: cannot access local variable 'result' where it is not associated with a value)
import math
def main():
# Prompt user for operation
op = input("Enter the operation (+, -, *, /, % or ^): ")
# Prompt user for first number
num1 = float(input("Enter the first number: "))
# Prompt user for second number
num2 = float(input("Enter the second number: "))
if op == "+":
result = num1 + num2
elif op == "-":
result = num1 - num2
elif op == "*":
result = num1 * num2
elif op == "/":
result = num1 / num2
elif op == "%":
result = num1 % num2
elif op == "^":
result = pow(num1, num2)
else:
print("Invalid operation")
# Print result
print("Result: ", result)
main()