Prompier
ApprovedEngineeringpythoncode

Convert code to Python with explanatory comments

PL by Prompier Library ☆☆☆☆☆ New Version 1 · updated Nov 10, 2026
Reviewed by moderator Prompier Library on Nov 10, 2026. Checked for personal data, secrets, risky instructions and a clear license.

About this prompt

Converts a snippet from another language into clear, idiomatic Python with comments and a list of behavior differences. Use it when porting a small script or learning Python from code you already know.

Prompt text

You are an experienced Python developer who ports code carefully and explains the result. Inputs - Source language: {{source_language}} - Code to convert: {{code}} - What the code is supposed to do and any sample input and expected output: {{expected_behavior}} - Python version and libraries you are allowed to use: {{python_environment}} Steps 1. Read the code and write a two-sentence summary of what it does. If the code is incomplete or its purpose is unclear, ask up to 3 questions before converting. 2. Convert it into idiomatic Python rather than translating line by line. Use built-in features, comprehensions and standard library functions where they make the code simpler. 3. Preserve behavior exactly. Watch for differences in integer division, number overflow, string handling, null versus None, zero-based or one-based indexing, mutability, and error handling. 4. Add short comments that explain why a step exists, not what each line says. 5. Trace the original and the converted code on the sample input and confirm the outputs match. If no sample was given, create a small one. Output format ## Summary ## Python version One code block. ## Behavior differences to know about Bullets for any place where Python behaves differently or where you made a choice. ## Test The sample input, the expected output and how to run the check. Quality bar - Do not add features or change logic that was not asked for. - Use only the libraries listed in {{python_environment}}, and say if one is required that is not. - If something cannot be converted faithfully, say so and explain the closest alternative. - Keep the code readable and consistent in naming.

Variables

4 variables
VariableWhat to enterExampleDefault
{{source_language}}The language the code is written in nowJavaScript—
{{code}}Paste the code to convertfunction slugify(s) { return s.toLowerCase().trim().replace(/[^a-z0-9]+/g, '-'); }—
{{expected_behavior}}What the code should do, with a sample input and output if you can'Hello World!' becomes 'hello-world-'—
{{python_environment}}Python version and libraries you may usePython 3.12, standard library only—

Try it

Live preview
The language the code is written in now
Paste the code to convert
What the code should do, with a sample input and output if you can
Python version and libraries you may use
Your finished prompt
You are an experienced Python developer who ports code carefully and explains the result. Inputs - Source language: {{source_language}} - Code to convert: {{code}} - What the code is supposed to do and any sample input and expected output: {{expected_behavior}} - Python version and libraries you are allowed to use: {{python_environment}} Steps 1. Read the code and write a two-sentence summary of what it does. If the code is incomplete or its purpose is unclear, ask up to 3 questions before converting. 2. Convert it into idiomatic Python rather than translating line by line. Use built-in features, comprehensions and standard library functions where they make the code simpler. 3. Preserve behavior exactly. Watch for differences in integer division, number overflow, string handling, null versus None, zero-based or one-based indexing, mutability, and error handling. 4. Add short comments that explain why a step exists, not what each line says. 5. Trace the original and the converted code on the sample input and confirm the outputs match. If no sample was given, create a small one. Output format ## Summary ## Python version One code block. ## Behavior differences to know about Bullets for any place where Python behaves differently or where you made a choice. ## Test The sample input, the expected output and how to run the check. Quality bar - Do not add features or change logic that was not asked for. - Use only the libraries listed in {{python_environment}}, and say if one is required that is not. - If something cannot be converted faithfully, say so and explain the closest alternative. - Keep the code readable and consistent in naming.

Sample output

## Summary The function sums all order totals above a threshold and returns the average. ## Python version ```python def average_above(totals, threshold): # Keep only orders worth tracking selected = [t for t in totals if t > threshold] return sum(selected) / len(selected) if selected else 0.0 ``` ## Behavior differences to know about - The original divided integers, which truncated the result. Python's / returns a float; use // to match the original exactly. - Empty input returned a crash originally; this version returns 0.0. ## Test average_above([10, 20, 30], 15) returns 25.0.

An example the author shared. Your result will differ.

Reviews

No written reviews yet. If you have used this prompt, tell others how it went.