Madewithwebsim / gGkNV0FsgoYjI7gM1.html
allknowingroger's picture
Upload 55 files
ad1dcd6 verified
raw
history blame
No virus
3.91 kB
<html><head><base href="https://websim.ai/python-bug-buster"><title>Python Bug Buster: Detect and Fix Bugs in Your Code</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/mode/python/python.min.js"></script>
</head>
<body class="bg-gray-100 min-h-screen font-sans">
<header class="bg-purple-600 text-white py-6">
<div class="container mx-auto px-4">
<h1 class="text-3xl font-bold">Python Bug Buster</h1>
<p class="mt-2">Detect and Fix Bugs in Your Python Code</p>
</div>
</header>
<main class="container mx-auto px-4 py-8">
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-2xl font-semibold mb-4">Code Editor</h2>
<textarea id="code-editor" class="w-full h-64 font-mono text-sm"></textarea>
<button id="analyze-button" class="mt-4 py-2 px-4 bg-purple-600 text-white rounded-md hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2">
Analyze and Fix Bugs
</button>
</div>
<div id="result-container" class="mt-8 bg-white rounded-lg shadow-md p-6 hidden">
<h2 class="text-2xl font-semibold mb-4">Analysis Result</h2>
<div id="bug-list" class="mb-4"></div>
<h3 class="text-xl font-semibold mb-2">Fixed Code:</h3>
<pre id="fixed-code" class="bg-gray-100 p-4 rounded-md overflow-x-auto"></pre>
</div>
</main>
<script>
let editor;
document.addEventListener('DOMContentLoaded', (event) => {
editor = CodeMirror.fromTextArea(document.getElementById("code-editor"), {
mode: "python",
lineNumbers: true,
theme: "default"
});
// Sample code with bugs
editor.setValue(`def calculate_average(numbers):
total = 0
for num in numbers
total += num
return total / len(numbers)
def main():
scores = [85, 92, 78, 90, 88]
average = calculate_average(scores)
print(f"The average score is: {average}"")
if __name__ == "__main__":
main()`);
});
document.getElementById('analyze-button').addEventListener('click', function() {
const code = editor.getValue();
analyzeAndFixCode(code);
});
function analyzeAndFixCode(code) {
// Simulate bug detection and fixing
setTimeout(() => {
const bugList = [
"Syntax error: Missing colon (:) after 'for' loop declaration",
"Syntax error: Extra quotation mark in print statement",
"Potential division by zero if 'numbers' list is empty"
];
const fixedCode = `def calculate_average(numbers):
if not numbers:
return 0 # Return 0 for empty list to avoid division by zero
total = 0
for num in numbers: # Added missing colon
total += num
return total / len(numbers)
def main():
scores = [85, 92, 78, 90, 88]
average = calculate_average(scores)
print(f"The average score is: {average}") # Removed extra quotation mark
if __name__ == "__main__":
main()`;
displayResults(bugList, fixedCode);
}, 1500);
}
function displayResults(bugList, fixedCode) {
const resultContainer = document.getElementById('result-container');
const bugListElement = document.getElementById('bug-list');
const fixedCodeElement = document.getElementById('fixed-code');
resultContainer.classList.remove('hidden');
bugListElement.innerHTML = '<h3 class="text-xl font-semibold mb-2">Detected Bugs:</h3><ul class="list-disc pl-5">' +
bugList.map(bug => `<li>${bug}</li>`).join('') +
'</ul>';
fixedCodeElement.textContent = fixedCode;
}
</script>
</body></html>