1
x = """
def test_add(a, b):
    add = a + b
    return add

test_add(10, 6)
"""
print(eval(x))

The above code produces following error:

File "<string>", line 2
    def test_add(a, b):
      ^
SyntaxError: invalid syntax

How can i fix this error ? Note : In this example, 16 should be printed to the console.

TheEagle
  • 5,808
  • 3
  • 11
  • 39
dine b
  • 39
  • 3

1 Answers1

-2

The eval() method can returns the result evaluated from the expression.

a = 10
b = 6
print(eval("a+b"))
  • 2
    Ok, and? How does that answer the question? You didn't explain why the code in the question doesn't work or how to fix it... – Tomerikoo Mar 21 '21 at 13:37