Python Playground
Run Python code in your browser with printed output, input() and tracebacks, with several files and optional packages, and a zip download.
What your program prints appears here. Press Run.
Shortcuts: Ctrl+Enter run · / search (use ⌘ on Mac)
Free Online Python Playground
Run Python code in your browser. Type a program on the left, press Run, and what it prints appears on the right, with input boxes for input() and short error messages that point at the line. Your code runs on your device and is never uploaded, so it is a safe place to try ideas, learn, or check a small script. Run Python in your browser: print output, answer input() prompts and use several files, without installing anything or uploading your code.
How to use the playground
- Write Python in main.py. The sample counts words, so you can change it and see what happens.
- Press Run (or Ctrl+Enter). The first time, the Python engine loads for a few seconds.
- If the program calls
input(), a box appears under the output: type your answer and press Enter. - Use Stop if a program does not finish. After the time limit it is stopped for you.
Several files and packages
Press + to add a file such as helpers.py, then write import helpers in main.py. Run starts the file you have open. The ⋯ menu downloads every file in one zip. For packages that are not part of Python itself, such as numpy, press Add packages: it downloads package files from cdn.jsdelivr.net and sends none of your code. Drawing with matplotlib is not available. If you also work with text patterns, the Regex Tester is handy, and the JavaScript Playground runs the same kind of experiment in another language.
Worked example
Paste this into main.py and press Run:
name = input("Your name? ")
scores = {"Ana": 3, "Ben": 5}
scores[name] = len(name) * 2
print(f"{name} scores {scores[name]}")
print(sorted(scores, key=scores.get, reverse=True))The program asks for a name. If you type Mia, the output is:
Your name? Mia Mia scores 6 ['Ben', 'Mia', 'Ana']
Common mistakes
- Mixing tabs and spaces to indent. Python needs the lines of one block to line up the same way.
- Forgetting the colon at the end of
if,for,defandwhilelines. - Importing a package such as numpy and expecting it to be there. Press Add packages first.
- Pressing Run while helpers.py is open: Run starts the open file, so open main.py.