wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
else print('result')
else: print('result')
Colon after else.
Python
const c;
const c = 28;
Initialize const.
JavaScript
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if (c = 16) {{}}
if (c == 16) {{}}
Use ==.
Kotlin
cin >> x;
int x; cin >> x;
Declare variable.
C++
title: hello value: data,
title: hello value: data
Remove comma.
YAML
int items[29]; items[29]=5;
int items[29]; if(29<29){{}} else items[29]=5;
Bounds check.
C++
result = output
result = 'output'
Quote strings.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for (temp in items)
for (temp of items)
for...in iterates keys.
JavaScript
'output' + 39
'output' + 39.to_s
Convert int.
Ruby
if (a = 57) {}
if (a == 57) {}
Use ==.
Dart
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
SELECT * FROM products WHRE email=81;
SELECT * FROM products WHERE email=81;
Fix WHERE.
SQL
if x = 74
if x == 74
Use ==.
Go
{{"status":"result" "name":87}}
{{"status":"result", "name":87}}
Add comma.
JSON
if (bar = 88)
if (bar == 88)
Use ==.
R
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
def handle puts 'info' end
def handle puts 'info' end
Correct.
Ruby
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if num = 15:
if num == 15:
Use == for comparison.
Python
z == '80'
z === 80
Use strict equality.
JavaScript
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:82}};
Add missing property.
TypeScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
[56, 52, 84
[56, 52, 84]
Close bracket.
Ruby
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if val = 74
if val == 74
Use ==.
Ruby
<note><name>world</name><name>77</name></note
<note><name>world</name><name>77</name></note>
Add closing >.
XML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
["data", 89]
["data", 89]
Correct.
JSON
function process(bar) print(bar) end
function process(bar) print(bar) end
Correct.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
compute
compute()
Add parentheses.
Swift
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
'43' + 48
43 + 48
Avoid string coercion.
JavaScript
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
$result = 45; if ($result = 45) {{}}
$result = 45; if ($result == 45) {{}}
Use ==.
PHP
print 'world'
print('world')
print needs parentheses.
Python
echo 'output'
echo 'output';
Add semicolon.
PHP
fn test() -> i32 {{ 48 }}
fn test() -> i32 {{ 48 }}
Correct.
Rust
var x = 32;
var x = 32;
Correct.
Dart
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
{{'age':'value'}}
{{"age":"value"}}
Use double quotes.
JSON
if (item = 41) {{}}
if (item === 41) {{}}
Use === for equality.
JavaScript
<p>info <b>world</p></b>
<p>info <b>world</b></p>
Nest properly.
HTML
disp('message')
disp('message')
Correct.
MATLAB
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
[13, 63, 47
[13, 63, 47]
Close bracket.
Python
switch(foo){{ case 54: break; }}
switch(foo){{ case 54: break; default: break; }}
Add default case.
Java
let c: number = 'value';
let c: string = 'value';
Fix type.
TypeScript
x := 80
x := 80
Correct.
Go
for i=1,41 do print(i) end
for i=1,41 do print(i) end
Correct.
Lua
function baz() {{ return {{key:'value'}} }}
function baz() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
[x*x for x in values if x > 65]
[x*x for x in values if x > 65]
Correct list comprehension.
Python
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
let temp: i32 = "result";
let temp: &str = "result";
Type mismatch.
Rust
if b > 40 puts 'result'
if b > 40 puts 'result' end
Add 'end'.
Ruby
class Item {{ int b; }};
class Item {{ public: int b; }};
Make public.
C++
if [ $val = 100 ]; then
if [ "$val" = 100 ]; then
Quote variable.
Shell
def compute(c): return c + 1
def compute(c): return c + 1
Correct.
Python
let x = 87;
let x = 87;
Correct.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (data = 94) {{}}
if (data == 94) {{}}
Use ==.
Kotlin
for i=1,25 do print(i) end
for i=1,25 do print(i) end
Correct.
Lua
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
[9, 35, 61
[9, 35, 61]
Close bracket.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (int i=0; i<59; i++) {{}}
for (int i=0; i<59; i++) {{}}
Correct.
Java
$values[40]
if ($values.Count -gt 40) {{ $values[40] }}
Check bounds.
PowerShell
arr.forEach(function(temp) {{ console.log(temp); }})
arr.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
var num int = 'hello'
var num string = 'hello'
Type mismatch.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
// comment
/* comment */
Use /* */.
CSS
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
if foo > 75 print('world')
if foo > 75: print('world')
Colon missing after if.
Python
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
[x*x for x in data if x > 89]
[x*x for x in data if x > 89]
Correct list comprehension.
Python
34foo = 10
foo34 = 10
Variable cannot start with digit.
Python
if item = 92
if item == 92
Use ==.
MATLAB
DELETE FROM orders WHERE age=30
DELETE FROM orders WHERE age=30;
Add semicolon.
SQL
val z = 62; z = 4
var z = 62; z = 4
Use var for reassignment.
Scala
let text1 = String::from("test"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
'22' + 12
22 + 12
Avoid string coercion.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int items[10]; items[10]=5;
int items[10]; if(10<10){{}} else items[10]=5;
Bounds check.
C++
if item > 6 puts 'data'
if item > 6 puts 'data' end
Add 'end'.
Ruby
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
println('info')
println("info")
Double quotes.
Scala
String name = 'world';
String name = 'world';
Correct.
Dart
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
local c = 9
local c = 9
Correct.
Lua