Converter
Python to Thunder converter
Paste Python and see it as Thunder: plain steps you can read, change, and run. Every line either converts with the same meaning or is marked as not translated, with the reason. It never guesses.
✓ 3 of 3 functions converted exactly.
Type or paste your own. It converts as you type, in your browser: nothing is sent anywhere.
In Thunder
To shipping cost:
Receive weight and express
When weight is at most 0:
Stop with "weight must be positive"
Set cost to 5 + (weight * 2)
When express is true:
Set cost to cost * 1.5
Give cost
To grade:
Receive score
When score is at least 90:
Give "A"
Otherwise when score is at least 80:
Give "B"
Otherwise when score is at least 70:
Give "C"
Give "F"
To total:
Receive prices
Set result to 0
For each price in prices:
Set result to result + price
Give resultWhat you get
- Each Python function as Thunder Core, the version of Thunder you can edit, run, and compile to six languages.
- A line Thunder Core can't say with the same meaning is marked not translated and becomes a line that stops with a clear error if it runs. Nothing is skipped quietly.
- Assumptions are written next to the code. For example,
if express:becomesWhen express is true, and stops with an error ifexpressis not yes or no, where Python would accept other values.
What converts today
- Functions with numbers, text, yes/no values, and lists;
if/elif/else;forloops; arithmetic;raise; and classes (each method becomes a function that receives the object). - Measured on 20 small Python functions: 19 convert exactly, and all 19 give the same results as the original Python on every sample input. See the measurements.
- Not yet:
try/except, and special methods such as__len__. These are marked not translated, with the reason.
The example, step by step
Written by the Thunder compiler 2.0.0 while this page was built, not by hand.
Python
def shipping_cost(weight, express):
"""Five dollars plus two per kilo; express costs half as much again."""
if weight <= 0:
raise ValueError("weight must be positive")
cost = 5 + weight * 2
if express:
cost = cost * 1.5
return cost
def grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
return "F"
def total(prices):
result = 0
for price in prices:
result = result + price
return resultThunder
To shipping cost:
Receive weight and express
When weight is at most 0:
Stop with "weight must be positive"
Set cost to 5 + (weight * 2)
When express is true:
Set cost to cost * 1.5
Give cost
To grade:
Receive score
When score is at least 90:
Give "A"
Otherwise when score is at least 80:
Give "B"
Otherwise when score is at least 70:
Give "C"
Give "F"
To total:
Receive prices
Set result to 0
For each price in prices:
Set result to result + price
Give resultOn your computer
The same conversion with the thunder command (Node.js 18+). Nothing is sent anywhere, and no AI is involved.
npm install -g @skillstech/thunderlang
thunder read shipping.py --as-core > shipping.thunder