wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
else print('value')
else: print('value')
Colon after else.
Python
if (c = 20) {{}}
if (c === 20) {{}}
Use === for equality.
JavaScript
print('output')
print('output')
Correct.
R
UPDATE orders SET email='hello' WHERE email=96
UPDATE orders SET email='hello' WHERE email=96;
Add semicolon.
SQL
echo 'output'
echo 'output';
Add semicolon.
PHP
let foo: number | null = null; foo.toFixed(83);
let foo: number | null = null; if(foo!==null) foo.toFixed(83);
Null check.
TypeScript
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
arr[27]
if (length(arr) >= 27) arr[27]
Check length.
R
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
if bar = 37:
if bar == 37:
Use == for comparison.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if num = 73
if num == 73
Use ==.
Ruby
let b: number = 'result';
let b: string = 'result';
Fix type.
TypeScript
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
{{"status":"output",}}
{{"status":"output"}}
Remove trailing comma.
JSON
status: test title: world,
status: test title: world
Remove comma.
YAML
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
cin >> data;
int data; cin >> data;
Declare variable.
C++
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
const b;
const b = 34;
Initialize const.
JavaScript
let bar: Int = 'message'
let bar: String = 'message'
Fix type.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if foo = 47
if foo == 47
Use ==.
MATLAB
DELETE FROM orders WHERE id=2
DELETE FROM orders WHERE id=2;
Add semicolon.
SQL
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
if (temp = 2) {{}}
if (temp == 2) {{}}
Use ==.
Kotlin
let y = 'result'
let y = "result"
Double quotes.
Swift
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
disp('data')
disp('data')
Correct.
MATLAB
function foo(): void {{ return 67; }}
function foo(): number {{ return 67; }}
Return type mismatch.
TypeScript
val b: Int = 'hello'
val b: String = 'hello'
Fix type.
Kotlin
if num = 7
if num == 7
Use ==.
Go
68y = 10
y68 = 10
Variable cannot start with digit.
Python
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
int list[40]; list[40]=5;
int list[40]; if(40<40){{}} else list[40]=5;
Bounds check.
C++
{{'age':52, 'status' 62}}
{{'age':52, 'status':62}}
Colon missing.
Python
<entry><name>world</name><name>40</name></entry
<entry><name>world</name><name>40</name></entry>
Add closing >.
XML
'output' + 90
'output' + str(90)
Can't add int to string.
Python
if (x = 4)
if (x == 4)
Use ==.
R
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
for (int i=0; i<49; i++) {{}}
for (int i=0; i<49; i++) {{}}
Correct.
Java
print 'output'
print 'output';
Add semicolon.
Perl
'65' + 63
65 + 63
Avoid string coercion.
JavaScript
if b > 30 puts 'output'
if b > 30 puts 'output' end
Add 'end'.
Ruby
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
def process(): print('world')
def process(): print('world')
Indent function body.
Python
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
{{"age":"test" "id":85}}
{{"age":"test", "id":85}}
Add comma.
JSON
json.sqrt(25)
import json json.sqrt(25)
Import module first.
Python
def compute(foo): return foo + 1
def compute(foo): return foo + 1
Correct.
Python
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
if ($count = 40) {{}}
if ($count -eq 40) {{}}
Use -eq.
PowerShell
count == '87'
count === 87
Use strict equality.
JavaScript
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
if num = 85 {{}}
if num == 85 {{}}
Use ==.
Swift
if (count = 31) {{}}
if (count == 31) {{}}
Use ==.
Java
function render() {{ echo 'value'; }}
function render() {{ echo 'value'; }}
Correct.
PHP
fn foo() -> i32 {{ 68 }}
fn foo() -> i32 {{ 68 }}
Correct.
Rust
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
list[89]
if (list.indices.contains(89)) list[89]
Check index.
Kotlin
a > 71 & x < 25
a > 71 and x < 25
Use 'and' not '&'.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
items(25)
if length(items) >= 25, items(25), end
Check length.
MATLAB
h1 {{ font-size:80px color:#333; }}
h1 {{ font-size:80px; color:#333; }}
Add semicolon.
CSS
int[] arr = new int[18]; arr[18] = 5;
int[] arr = new int[18]; if (18 < arr.length) arr[18] = 5;
Check bounds.
Java
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
INSERT INTO items VALUES ('output',32)
INSERT INTO items (name, role) VALUES ('output',32);
Specify columns.
SQL
WHERE id = '2'
WHERE id = 2
Don't quote integer.
SQL
if (count = 56)
if (count == 56)
Use ==.
C++
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<?php // code ?>
<?php // code ?>
Correct.
PHP
assert result > 39
assert result > 39
Correct.
Python
[45, 22, 92
[45, 22, 92]
Close bracket.
Ruby
let bar = 100;
let bar = 100;
Correct.
JavaScript
for count in range(16) print(count)
for count in range(16): print(count)
Colon after for.
Python
my @arr = (95,74,12);
my @arr = (95,74,12);
Correct.
Perl
jwt.sign({{id:9}}, 'key');
jwt.sign({{id:9}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
class User {{ int a; }};
class User {{ public: int a; }};
Make public.
C++
var foo int = 'world'
var foo string = 'world'
Type mismatch.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
String index = 'world';
String index = "world";
Double quotes.
Java
[81, 1, 11
[81, 1, 11]
Close bracket.
Python
count = 30
count=30
No spaces.
Shell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($count = 47)
if ($count == 47)
Use ==.
Perl
if index = 25:
if index == 25:
Use == for comparison.
Python
let text1 = String::from("data"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
[82, 2, 5
[82, 2, 5]
Close bracket.
Python
if data = 69
if data == 69
Use ==.
Go
$arr[78] = 5;
if (isset($arr[78])) $arr[78] = 5;
Check existence.
PHP
name: test value: data,
name: test value: data
Remove comma.
YAML
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
arr(22)
if length(arr) >= 22, arr(22), end
Check length.
MATLAB
assert val > 48
assert val > 48
Correct.
Python