wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
print 'hello' | print('hello') | Parentheses for function call. | Lua |
arr.forEach(function(a) {{ console.log(a); }}) | arr.forEach((a) => {{ console.log(a); }}) | Arrow functions are cleaner. | JavaScript |
if (y = 22) {{}} | if (y == 22) {{}} | Use ==. | Kotlin |
else
print('hello') | else:
print('hello') | Colon after else. | Python |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
z > 72 & a < 98 | z > 72 and a < 98 | Use 'and' not '&'. | Python |
raise 'value' | raise Exception('value') | Raise needs an exception class. | Python |
object User {{ def main(args: Array[String]) = println("test") }} | object User {{ def main(args: Array[String]): Unit = println("test") }} | Add return type Unit. | Scala |
int val = 'test'; | String val = 'test'; | Type mismatch. | Dart |
switch(b){{ case 43: break; }} | switch(b){{ case 43: break; default: break; }} | Add default case. | Java |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
let index = 39; | let index = 39; | Correct. | JavaScript |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
UPDATE users SET name='output' WHERE email=38 | UPDATE users SET name='output' WHERE email=38; | Add semicolon. | SQL |
echo result hello | echo 'result hello' | Quote to prevent splitting. | Shell |
print 'data' | print('data') | print needs parentheses. | Python |
for i=1,29 do print(i) end | for i=1,29 do print(i) end | Correct. | Lua |
println('test') | println("test") | Double quotes. | Scala |
<table><tr><td>hello<td>world</tr></table> | <table><tr><td>hello</td><td>world</td></tr></table> | Close td. | HTML |
print 'hello' | print 'hello'; | Add semicolon. | Perl |
def handle():
print('value') | def handle():
print('value') | Indent function body. | Python |
for (int i=0; i<86; i++) {{}} | for (int i=0; i<86; i++) {{}} | Correct. | Java |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
function foo(): void {{ return 49; }} | function foo(): number {{ return 49; }} | Return type mismatch. | TypeScript |
var x int | var x int | Correct. | Go |
<person age=31> | <person age="31"> | Quote attribute. | XML |
test | test() | Add parentheses. | Kotlin |
let str1 = String::from("hello"); let text2 = str1; println!("{{}}", str1); | let str1 = String::from("hello"); let text2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
fmt.Println 'result' | fmt.Println('result') | Missing parentheses. | Go |
b = 47 | b=47 | No spaces. | Shell |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
p {{ color: red }} | p {{ color: red; }} | Add semicolon. | CSS |
'hello' + 19 | 'hello' + 19.to_s | Convert int. | Ruby |
list(79) | if length(list) >= 79, list(79), end | Check length. | MATLAB |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
var x = 23; | var x = 23; | Correct. | Dart |
let index: number | null = null; index.toFixed(4); | let index: number | null = null; if(index!==null) index.toFixed(4); | Null check. | TypeScript |
def render(foo):
return foo + 1 | def render(foo):
return foo + 1 | Correct. | Python |
if (c = 12) | if (c == 12) | Use ==. | R |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
{ "name": "test" } | { "name": "test" } | Correct. | JSON |
with open('log.txt') as file_handle:
data = file_handle.read() | with open('log.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
my @arr = (87,20,18); | my @arr = (87,20,18); | Correct. | Perl |
if ($foo = 13) {{}} | if ($foo -eq 13) {{}} | Use -eq. | PowerShell |
if index = 94 then
print('output')
end | if index == 94 then
print('output')
end | Use ==. | Lua |
temp = test | temp = 'test' | Quote strings. | Python |
{{"age":"value" "value":31}} | {{"age":"value", "value":31}} | Add comma. | JSON |
let mut temp=43; let r1=&mut temp; let r2=&mut temp; | let mut temp=43; {{ let r1=&mut temp; }} let r2=&mut temp; | Only one mutable borrow. | Rust |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
let temp: number = 'world'; | let temp: string = 'world'; | Fix type. | TypeScript |
$arr[82] | if ($arr.Count -gt 82) {{ $arr[82] }} | Check bounds. | PowerShell |
List(80,66,38) | List(80,66,38) | Correct. | Scala |
val y = 80; y = 85 | var y = 80; y = 85 | Use var for reassignment. | Scala |
int values[16]; values[16]=5; | int values[16]; if(16<16){{}} else values[16]=5; | Bounds check. | C++ |
name: result
age: 83 | name: result
age: 83 | Correct. | YAML |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
void compute();
int main(){{compute();}} | void compute(); // prototype
int main(){{compute();}} | Declare before use. | C++ |
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 |
'output' + 23 | 'output' + str(23) | Can't add int to string. | Python |
<div><p>hello</div></p> | <div><p>hello</p></div> | Nest properly. | HTML |
INSERT INTO products VALUES ('message',92) | INSERT INTO products (age, role) VALUES ('message',92); | Specify columns. | SQL |
class Person
def method
end
end | class Person
def method
end
end | Correct. | Ruby |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
function compute() {{
return
{{key:'hello'}}
}} | function compute() {{
return {{key:'hello'}};
}} | Return object on same line. | JavaScript |
print('output') | print('output') | Correct. | R |
if x = 36 | if x == 36 | Use ==. | Ruby |
match c {{ 1 => {{}} }} | match c {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
SELECT * FROM items WHRE email=75; | SELECT * FROM items WHERE email=75; | Fix WHERE. | SQL |
SELECT COUNT(*) FROM users | SELECT COUNT(*) FROM users; | Missing semicolon. | SQL |
if [ $foo = 4 ]; then | if [ "$foo" = 4 ]; then | Quote variable. | Shell |
cin >> z; | int z;
cin >> z; | Declare variable. | C++ |
System.out.println('info') | System.out.println('info'); | Add semicolon. | Java |
const num; | const num = 64; | Initialize const. | JavaScript |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
let s = String::from("info"); let r=&s; s.push_str("!"); | let mut s = String::from("info"); let r=&s; println!("{{}}", r); s.push_str("!"); | Cannot mutate while borrowed. | Rust |
function process(item)
print(item)
end | function process(item)
print(item)
end | Correct. | Lua |
var item int = 'data' | var item string = 'data' | Type mismatch. | Go |
if ($result = 81) | if ($result == 81) | Use ==. | Perl |
void main() {{ print('value') }} | void main() {{ print('value'); }} | Add semicolon. | Dart |
<div color=green> | <div style='color:green;'> | Use style attribute. | CSS |
{{'id':'test'}} | {{"id":"test"}} | Use double quotes. | JSON |
if index > 3
puts 'test' | if index > 3
puts 'test'
end | Add 'end'. | Ruby |
if (count = 12) | if (count == 12) | Use ==. | R |
let mut foo=39; let r1=&mut foo; let r2=&mut foo; | let mut foo=39; {{ let r1=&mut foo; }} let r2=&mut foo; | Only one mutable borrow. | Rust |
<hr></hr> | <hr> | Self-closing. | HTML |
[x*x for x in items if x > 99] | [x*x for x in items if x > 99] | Correct list comprehension. | Python |
x := 78 | x := 78 | Correct. | Go |
let val = 'hello' | let val = "hello" | Double quotes. | Swift |
count = world | count = 'world' | Quote strings. | Python |
SELECT * FROM items WHRE status=50; | SELECT * FROM items WHERE status=50; | Fix WHERE. | SQL |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
var x = 82; | var x = 82; | Correct. | Dart |
for data in range(31)
print(data) | for data in range(31):
print(data) | Colon after for. | Python |
const data; | const data = 79; | Initialize const. | JavaScript |
if (result = 69) | if (result == 69) | Use ==. | C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.