program = input('Enter code to be executed: ')
exec(program)
programs = {'do_something': lambda: print("Do something")}
program = input('Enter a program code to be used: ')
if programs.get(program):
programs[program]()
Used when you use the exec
statement (function for Python 3), to discourage
its usage. That doesn’t mean you cannot use it! It’s dangerous to use this
function for a user input.