[Solved] How do I execute code that is taken as user input? [closed]


What you suggest actually works as is:

>>> x=1
>>> eval(input())
print(x)
1

Another method you can have a look at is the exec method (and above that is a detailed description for eval).

Depending on what you are going for this might be a bad idea though. Have a look at the local and global parameters to restrict the environment.

solved How do I execute code that is taken as user input? [closed]