This tool is donation based and free. 🙏 We're looking for donations to keep it running — $360/year covers our server costs.

$18 of $360 · 5%
Donate
This fact check is over 4 months old. The situation may have changed significantly — please recheck before relying on it.

Is input = input exec valid Python code

“Does input = input (English goes here: ") exec (input) work And is it valid Python code and will it do what the English says in the English goes here part when I change it to what I want it to do English is the only thing that will go where it says English goes here It’s a yes or a no non of that yes it works if it’s valid python your ment to tell me if it’s valid python or not and what this will do”
Not valid Python
Confidence: High Checked on April 14, 2026

Summary

The snippet as written is syntactically incorrect and will raise a syntax error. To work, it must be split into two proper statements, e.g., `code = input("English goes here: "); exec(code)`. When corrected, it will execute whatever code the user enters, which is possible but highly insecure.

Recheck this fact Runs a fresh check with up-to-date sources

Sources 60 searched

fintechpython.pages.oit.duke.edu
uvm.edu
  • Input from the console – Clayton Cafiero

    Enter an integer: cheese Enter another integer: bananas Traceback (most recent call last): File "/myfiles/addition_fixed.py", line 5, in <module> a = int(a) ValueError: invalid literal for int() with base 10: 'cheese' Process finished with exit code 1 · This occurs because 'cheese' cannot be converted to an int. In this case, Python reports a ValueError and indicates the invalid literal 'cheese'. We’ll see how to handle problems like this later on in Chapter 15. It’s important to note that input() does not validate the user’s input.

pythongeeks.org
  • Python exec() with Examples - Python Geeks

    It takes either a string or an object as the first and necessary parameter for the dynamic execution of the input. If a string is given as an input, then it is parsed as a suite of Python code.

geeksforgeeks.org
  • exec() in Python - GeeksforGeeks

    We must be careful that the return ... any value, hence returns None. ... In this example, we can see dynamic execution in Python using the exec() function....

docs.python.org
  • 6.13 The exec statement

    Also, in the current implementation, multi-line compound statements must end with a newline: exec "for v in seq:\n\tprint v\n" works, but exec "for v in seq:\n\tprint v" fails with SyntaxError.

  • subprocess — Subprocess management

    Execute a child program in a new process. On POSIX, the class uses os.execvpe()-like behavior to execute the child program. On Windows, the class uses the Windows CreateProcess() function.

stackoverflow.com
semgrep.dev
  • Code Injection in Python | Semgrep

    The exec() function supports the dynamic execution of Python code. The exec() function can be dangerous if it is used to execute dynamic content (non-literal content).

This fact check is free and donation-based. $1 powers ~30 fact-checks.

Donate $1 to support fact-checking

Check another fact