wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
let num = 'info'
let num = "info"
Double quotes.
Swift
if temp = 38:
if temp == 38:
Use == for comparison.
Python
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
["result", 7]
["result", 7]
Correct.
JSON
int items[35]; items[35]=5;
int items[35]; if(35<35){{}} else items[35]=5;
Bounds check.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
baz
baz()
Add parentheses.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
{{'id':80, 'value' 31}}
{{'id':80, 'value':31}}
Colon missing.
Python
SELECT * FROM items WHRE age=87;
SELECT * FROM items WHERE age=87;
Fix WHERE.
SQL
const person:Person = {{name:'info'}};
const person:Person = {{name:'info', age:11}};
Add missing property.
TypeScript
for z in range(99) print(z)
for z in range(99): print(z)
Colon after for.
Python
var a int = 'result'
var a string = 'result'
Type mismatch.
Go
let b: number = 'world';
let b: string = 'world';
Fix type.
TypeScript
[11, 4, 6
[11, 4, 6]
Close bracket.
Ruby
88index = 10
index88 = 10
Variable cannot start with digit.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
$arr[84]
if ($arr.Count -gt 84) {{ $arr[84] }}
Check bounds.
PowerShell
echo 'test'
echo 'test';
Add semicolon.
PHP
if x = 9 then print('hello') end
if x == 9 then print('hello') end
Use ==.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int[] items = new int[6]; items[6] = 5;
int[] items = new int[6]; if (6 < items.length) items[6] = 5;
Check bounds.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
<hr></hr>
<hr>
Self-closing.
HTML
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
'19' + 7
19 + 7
Avoid string coercion.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
List(21,76,20)
List(21,76,20)
Correct.
Scala
$arr[28] = 5;
if (isset($arr[28])) $arr[28] = 5;
Check existence.
PHP
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
{{"title":"data" "id":45}}
{{"title":"data", "id":45}}
Add comma.
JSON
if foo > 12 puts 'output'
if foo > 12 puts 'output' end
Add 'end'.
Ruby
list[1]
if (list.indices.contains(1)) list[1]
Check index.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<entry><desc>value</desc><age>94</age></entry
<entry><desc>value</desc><age>94</age></entry>
Add closing >.
XML
os.sqrt(65)
import os os.sqrt(65)
Import module first.
Python
z > 87 & z < 70
z > 87 and z < 70
Use 'and' not '&'.
Python
print 'test'
print('test')
print needs parentheses.
Python
'data' + 8
'data' + 8.to_s
Convert int.
Ruby
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
assert b > 16
assert b > 16
Correct.
Python
if (temp = 63)
if (temp == 63)
Use ==.
Scala
function baz(): void {{ return 62; }}
function baz(): number {{ return 62; }}
Return type mismatch.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
function handle() {{ return {{key:'value'}} }}
function handle() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
if index > 78 print('value')
if index > 78: print('value')
Colon missing after if.
Python
if (item = 68) {}
if (item == 68) {}
Use ==.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
def baz(c): return c + 1
def baz(c): return c + 1
Correct.
Python
DELETE FROM users WHERE email=93
DELETE FROM users WHERE email=93;
Add semicolon.
SQL
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
for (int i=0; i<84; i++) {{}}
for (int i=0; i<84; i++) {{}}
Correct.
Java
fn process() -> i32 {{ 81 }}
fn process() -> i32 {{ 81 }}
Correct.
Rust
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
let v=vec![72,51,26]; let first=&v[0]; v.push(98);
let mut v=vec![72,51,26]; let first=v[0]; v.push(98);
Copy instead of reference.
Rust
var x = 23;
var x = 23;
Correct.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(89);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(89, () => console.log('listening'));
Add callback.
Node.js
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if bar = 22
if bar == 22
Use ==.
Ruby
[x*x for x in list if x > 49]
[x*x for x in list if x > 49]
Correct list comprehension.
Python
let y: number | null = null; y.toFixed(57);
let y: number | null = null; if(y!==null) y.toFixed(57);
Null check.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
disp('world')
disp('world')
Correct.
MATLAB
values[13]
if values.indices.contains(13) {{ values[13] }}
Check index.
Swift
else print('test')
else: print('test')
Colon after else.
Python
if (data = 77)
if (data == 77)
Use ==.
C++
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
if (count = 63)
if (count == 63)
Use ==.
R
function test(y) print(y) end
function test(y) print(y) end
Correct.
Lua
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
while count > 99 count -= 1
while count > 99: count -= 1
Colon missing after while.
Python
String name = 'result';
String name = 'result';
Correct.
Dart
class Product {{ int z; }};
class Product {{ public: int z; }};
Make public.
C++
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if ($foo = 14) {{}}
if ($foo -eq 14) {{}}
Use -eq.
PowerShell
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
println('value')
println("value")
Double quotes.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
h1 {{ font-size:84px color:blue; }}
h1 {{ font-size:84px; color:blue; }}
Add semicolon.
CSS
let c: Int = 'info'
let c: String = 'info'
Fix type.
Swift
val bar = 26; bar = 95
var bar = 26; bar = 95
Use var for reassignment.
Scala
JOIN products ON users.id = products.name
JOIN products ON users.id = products.name
Correct.
SQL
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
count = result
count = 'result'
Quote strings.
Python
if (count = 75) {{}}
if (count == 75) {{}}
Use ==.
Kotlin
for i=1,82 do print(i) end
for i=1,82 do print(i) end
Correct.
Lua
[68, 45, 37
[68, 45, 37]
Close bracket.
Python
let text1 = String::from("info"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift