Spaces:
Runtime error
Runtime error
venky2k1
commited on
Commit
·
eef3533
1
Parent(s):
7f97eae
Final working bug fixer with fixed detection and suggestion
Browse files- bug_detector.py +0 -1
- fix_generator.py +3 -3
bug_detector.py
CHANGED
@@ -15,6 +15,5 @@ def detect_bug(code):
|
|
15 |
if __name__ == "__main__":
|
16 |
sample = "def multiply(a, b): return a + b"
|
17 |
print(detect_bug(sample))
|
18 |
-
|
19 |
#detects if there's a bug in code
|
20 |
|
|
|
15 |
if __name__ == "__main__":
|
16 |
sample = "def multiply(a, b): return a + b"
|
17 |
print(detect_bug(sample))
|
|
|
18 |
#detects if there's a bug in code
|
19 |
|
fix_generator.py
CHANGED
@@ -2,13 +2,13 @@ def generate_fix(code):
|
|
2 |
lines = code.split("\n")
|
3 |
fixed_lines = []
|
4 |
for line in lines:
|
5 |
-
line
|
6 |
-
|
7 |
-
content = line[6:].strip()
|
8 |
fixed_lines.append(f"print({content})")
|
9 |
else:
|
10 |
fixed_lines.append(line)
|
11 |
return "\n".join(fixed_lines)
|
|
|
12 |
# Optional test
|
13 |
if __name__ == "__main__":
|
14 |
buggy = "a = input()\nprint a"
|
|
|
2 |
lines = code.split("\n")
|
3 |
fixed_lines = []
|
4 |
for line in lines:
|
5 |
+
if line.strip().startswith("print ") and not line.strip().startswith("print("):
|
6 |
+
content = line.strip()[6:].strip()
|
|
|
7 |
fixed_lines.append(f"print({content})")
|
8 |
else:
|
9 |
fixed_lines.append(line)
|
10 |
return "\n".join(fixed_lines)
|
11 |
+
|
12 |
# Optional test
|
13 |
if __name__ == "__main__":
|
14 |
buggy = "a = input()\nprint a"
|