Paste broken code and get fixes with clear explanations. Torki identifies bugs, suggests optimizations, and rewrites with improvements — supporting Python, JavaScript, SQL, and more.
Try in TorkiDrop in the function, query, or file that isn't working. Include any error messages you're seeing. Torki works with Python, JavaScript, TypeScript, SQL, PHP, Go, Rust, and most popular languages.
This Python function should calculate compound interest but it's giving wrong results: def compound_interest(principal, rate, years) amount = principal * (1 + rate) ** years interest = amount - principl return interest
Torki identifies every bug, explains why it's wrong, and provides the corrected code. It doesn't just fix — it teaches you what went wrong so you can avoid similar mistakes.
Beyond fixing bugs, ask Torki to optimize for performance, add error handling, write tests, or refactor for readability. It understands the broader context of your code.
def compound_interest(principal, rate, years)
amount = principal * (1 + rate) ** years
interest = amount - principl
return interest
: after the parameter list.
2. Typo: principl → should be principal (missing 'a').
3. Rate should be divided by 100 if passed as a percentage (e.g., 5 for 5%).
Fixed code:
def compound_interest(principal, rate, years):
"""Calculate compound interest.
rate: annual rate as percentage (e.g., 5 for 5%)
"""
decimal_rate = rate / 100
amount = principal * (1 + decimal_rate) ** years
interest = amount - principal
return round(interest, 2)
Test it:
>>> compound_interest(1000, 5, 10)
628.89 # $1000 at 5% for 10 yearsPaste your broken code. Torki finds the bugs, explains them, and gives you the fix.
Try in Torki