I'm trying to make a python program that when you input a code, it executes it. It has 2 problems and I need to fix it. I want it when you executed the code, it gets stored in a variable
I want't the result will be:
You executed [code] and the result was: [result]
now if I'm gonna do this:
code = 'print("hello world")'
interpreted = exec(code)
print(f"You executed {code} and the result was: {interpreted}")
this shows:
hello world
You executed print("hello world") and the result was: None
It returns none and the executed code was at the top I want to get rid of 'none'.
2nd: when i type print('hello') it throws an error
File "main.py", line 1
code = 'print('hello world')'
^
SyntaxError: invalid syntax
hello world becomes an invalid syntax how do I fix problem 1 and 2? Thanks in advance :)
codestatement.code = "print('hello world')"printfunction dont return anything so output will be alwaysnonefor print statement