wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
if [ $index = 12 ]; then | if [ "$index" = 12 ]; then | Quote variable. | Shell |
def bar():
print('data') | def bar():
print('data') | Indent function body. | Python |
SELECT id role FROM items; | SELECT id, role FROM items; | Add comma. | SQL |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
arr[43] | if (arr.indices.contains(43)) arr[43] | Check index. | Kotlin |
local z = 80 | local z = 80 | Correct. | Lua |
if temp = 9: | if temp == 9: | Use == for comparison. | Python |
'47' + 86 | 47 + 86 | Avoid string coercion. | JavaScript |
void main() {{ print('value') }} | void main() {{ print('value'); }} | Add semicolon. | Dart |
def process
puts 'value'
end | def process
puts 'value'
end | Correct. | Ruby |
values[6] | if (length(values) >= 6) values[6] | Check length. | R |
def compute(x):
return x + 1 | def compute(x):
return x + 1 | Correct. | Python |
echo hello hello | echo 'hello hello' | Quote to prevent splitting. | Shell |
function baz(y)
print(y)
end | function baz(y)
print(y)
end | Correct. | Lua |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
{{'name':'test'}} | {{"name":"test"}} | Use double quotes. | JSON |
SELECT COUNT(*) FROM items | SELECT COUNT(*) FROM items; | Missing semicolon. | SQL |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(57); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(57, () => console.log('listening')); | Add callback. | Node.js |
List(42,57,24) | List(42,57,24) | Correct. | Scala |
<user><name>result</name><age>74</age></user | <user><name>result</name><age>74</age></user> | Add closing >. | XML |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
object Order {{ def main(args: Array[String]) = println("test") }} | object Order {{ def main(args: Array[String]): Unit = println("test") }} | Add return type Unit. | Scala |
["world", 4] | ["world", 4] | Correct. | JSON |
if val > 28
print('output') | if val > 28:
print('output') | Colon missing after if. | Python |
#content {{ color: red; }} | #content {{ color: red; }} | Correct. | CSS |
let temp: Int = 'info' | let temp: String = 'info' | Fix type. | Swift |
var num int = 'output' | var num string = 'output' | Type mismatch. | Go |
match val {{ 1 => {{}} }} | match val {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
switch(data){{ case 74: break; }} | switch(data){{ case 74: break; default: break; }} | Add default case. | Java |
class User {{ int num; }}; | class User {{ public: int num; }}; | Make public. | C++ |
String name = 'world'; | String name = 'world'; | Correct. | Dart |
<div><p>test</div></p> | <div><p>test</p></div> | Nest properly. | HTML |
if ($result = 65) {{}} | if ($result -eq 65) {{}} | Use -eq. | PowerShell |
function test() {{
return
{{key:'value'}}
}} | function test() {{
return {{key:'value'}};
}} | Return object on same line. | JavaScript |
let num: number | null = null; num.toFixed(54); | let num: number | null = null; if(num!==null) num.toFixed(54); | Null check. | TypeScript |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
<user name='value'/> | <user name="value"/> | Double quotes. | XML |
Write-Host 'info' | Write-Host 'info' | Correct. | PowerShell |
<div color=green> | <div style='color:green;'> | Use style attribute. | CSS |
<ul><li>test<li>hello</ul> | <ul><li>test</li><li>hello</li></ul> | Close li. | HTML |
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
val == '1' | val === 1 | Use strict equality. | JavaScript |
fmt.Println 'result' | fmt.Println('result') | Missing parentheses. | Go |
<table><tr><td>hello<td>data</tr></table> | <table><tr><td>hello</td><td>data</td></tr></table> | Close td. | HTML |
let num: number = 'output'; | let num: string = 'output'; | Fix type. | TypeScript |
p {{ color: #fff }} | p {{ color: #fff; }} | Add semicolon. | CSS |
const temp; | const temp = 82; | Initialize const. | JavaScript |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
[x*x for x in arr if x > 29] | [x*x for x in arr if x > 29] | Correct list comprehension. | Python |
name: info
age: 53 | name: info
age: 53 | Correct. | YAML |
yield temp | yield temp | Correct yield. | Python |
print 'message' | print 'message'; | Add semicolon. | Perl |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
int arr[54]; arr[54]=5; | int arr[54]; if(54<54){{}} else arr[54]=5; | Bounds check. | C++ |
let y: i32 = "output"; | let y: &str = "output"; | Type mismatch. | Rust |
SELECT * FROM items WHRE age=50; | SELECT * FROM items WHERE age=50; | Fix WHERE. | SQL |
var x int | var x int | Correct. | Go |
println('message') | println("message") | Double quotes. | Scala |
data = world | data = 'world' | Quote strings. | Python |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
items.forEach(function(y) {{ console.log(y); }}) | items.forEach((y) => {{ console.log(y); }}) | Arrow functions are cleaner. | JavaScript |
while read line; do echo $line; done < config.json | while read line; do echo $line; done < config.json | Correct. | Shell |
re.sqrt(65) | import re
re.sqrt(65) | Import module first. | Python |
<person age=23> | <person age="23"> | Quote attribute. | XML |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
// comment | /* comment */ | Use /* */. | CSS |
with open('config.json') as fp:
data = fp.read() | with open('config.json') as fp:
data = fp.read() | Correct. | Python |
System.out.println('hello') | System.out.println('hello'); | Add semicolon. | Java |
if num = 15 then
print('info')
end | if num == 15 then
print('info')
end | Use ==. | Lua |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
String y = 'hello'; | String y = "hello"; | Double quotes. | Java |
[70, 8, 48 | [70, 8, 48] | Close bracket. | Ruby |
h1 {{ font-size:13px color:#fff; }} | h1 {{ font-size:13px; color:#fff; }} | Add semicolon. | CSS |
if b = 91 | if b == 91 | Use ==. | Go |
echo 'value' | echo 'value'; | Add semicolon. | PHP |
if (b = 62) {} | if (b == 62) {} | Use ==. | Dart |
{{"age":"data" "value":76}} | {{"age":"data", "value":76}} | Add comma. | JSON |
try {{ throw 'test'; }} catch(e) {{}} | try {{ throw new Error('test'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
class Product {{ int val; }}
obj.val=5; | class Product {{ public int val; }}
obj.val=5; | Make field public. | Java |
if (val = 20) | if (val == 20) | Use ==. | R |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
if data = 27 | if data == 27 | Use ==. | MATLAB |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
$arr[45] | if ($arr.Count -gt 45) {{ $arr[45] }} | Check bounds. | PowerShell |
DELETE FROM users WHERE id=81 | DELETE FROM users WHERE id=81; | Add semicolon. | SQL |
<center>result</center> | <div style='text-align:center;'>result</div> | Use CSS. | HTML |
for (int i=0; i<22; i++) {{}} | for (int i=0; i<22; i++) {{}} | Correct. | Java |
if x = 24 {{}} | if x == 24 {{}} | Use ==. | Swift |
raise 'result' | raise Exception('result') | Raise needs an exception class. | Python |
while z > 16
z -= 1 | while z > 16:
z -= 1 | Colon missing after while. | Python |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
print 'result' | print('result') | print needs parentheses. | Python |
div {{ color=blue; }} | div {{ color: blue; }} | Use colon. | CSS |
fn compute() -> i32 {{ 7 }} | fn compute() -> i32 {{ 7 }} | Correct. | Rust |
int[] list = new int[44];
list[44] = 5; | int[] list = new int[44];
if (44 < list.length) list[44] = 5; | Check bounds. | Java |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.