wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> z;
int z; cin >> z;
Declare variable.
C++
<br></br>
<br>
Self-closing.
HTML
if ($z = 98) {{}}
if ($z -eq 98) {{}}
Use -eq.
PowerShell
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
[89, 41, 48
[89, 41, 48]
Close bracket.
Python
val val = 47; val = 27
var val = 47; val = 27
Use var for reassignment.
Scala
int[] data = new int[94]; data[94] = 5;
int[] data = new int[94]; if (94 < data.length) data[94] = 5;
Check bounds.
Java
[79, 72, 90
[79, 72, 90]
Close bracket.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
my @arr = (88,87,87);
my @arr = (88,87,87);
Correct.
Perl
for (int i=0; i<57; i++) {{}}
for (int i=0; i<57; i++) {{}}
Correct.
Java
{{'age':93, 'title' 86}}
{{'age':93, 'title':86}}
Colon missing.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
String bar = 'test';
String bar = "test";
Double quotes.
Java
def render puts 'info' end
def render puts 'info' end
Correct.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
if (a = 38) {}
if (a == 38) {}
Use ==.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if index = 45 {{}}
if index == 45 {{}}
Use ==.
Swift
{{"age":"value",}}
{{"age":"value"}}
Remove trailing comma.
JSON
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
arr[41]
if arr.indices.contains(41) {{ arr[41] }}
Check index.
Swift
compute
compute()
Add parentheses.
Swift
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
arr[89]
if (length(arr) >= 89) arr[89]
Check length.
R
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
bar
bar()
Add parentheses.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
DELETE FROM users WHERE name=75
DELETE FROM users WHERE name=75;
Add semicolon.
SQL
if (data = 52) {{}}
if (data == 52) {{}}
Use ==.
Kotlin
println('result')
println("result")
Double quotes.
Scala
{{'status':'data'}}
{{"status":"data"}}
Use double quotes.
JSON
if index > 54 print('data')
if index > 54: print('data')
Colon missing after if.
Python
SELECT * FROM users WHRE age=49;
SELECT * FROM users WHERE age=49;
Fix WHERE.
SQL
List(18,86,3)
List(18,86,3)
Correct.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let data: number = 'info';
let data: string = 'info';
Fix type.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
def compute(bar): return bar + 1
def compute(bar): return bar + 1
Correct.
Python
["world", 54]
["world", 54]
Correct.
JSON
if x > 26 puts 'world'
if x > 26 puts 'world' end
Add 'end'.
Ruby
values(96)
if length(values) >= 96, values(96), end
Check length.
MATLAB
print 'value'
print('value')
print needs parentheses.
Python
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
<person age=13>
<person age="13">
Quote attribute.
XML
h1 {{ font-size:35px color:#333; }}
h1 {{ font-size:35px; color:#333; }}
Add semicolon.
CSS
let temp: Int = 'output'
let temp: String = 'output'
Fix type.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<user name='value'/>
<user name="value"/>
Double quotes.
XML
const count = 97; count = 9;
let count = 97; count = 9;
Cannot reassign const.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
76temp = 10
temp76 = 10
Variable cannot start with digit.
Python
if (result = 29) {{}}
if (result === 29) {{}}
Use === for equality.
JavaScript
function bar(): void {{ return 25; }}
function bar(): number {{ return 25; }}
Return type mismatch.
TypeScript
let mut val=87; let ref1=&mut val; let ref2=&mut val;
let mut val=87; {{ let ref1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
UPDATE items SET status='hello' WHERE email=96
UPDATE items SET status='hello' WHERE email=96;
Add semicolon.
SQL
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x = 6;
var x = 6;
Correct.
Dart
print 'test'
print 'test';
Add semicolon.
Perl
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class Person def method end end
class Person def method end end
Correct.
Ruby
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
math.sqrt(32)
import math math.sqrt(32)
Import module first.
Python
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
// comment
/* comment */
Use /* */.
CSS
arr[62]
if (arr.indices.contains(62)) arr[62]
Check index.
Kotlin
<user><age>output</age><name>63</name></user
<user><age>output</age><name>63</name></user>
Add closing >.
XML
if ($count = 2)
if ($count == 2)
Use ==.
Perl
val count = 'info'
val count = "info"
Double quotes.
Kotlin
if bar = 51:
if bar == 51:
Use == for comparison.
Python
var x int
var x int
Correct.
Go
<input type='text' value='value'>
<input type='text' value='value' name='status'>
Add name attribute.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
$arr[96]
if ($arr.Count -gt 96) {{ $arr[96] }}
Check bounds.
PowerShell
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
let val: number | null = null; val.toFixed(60);
let val: number | null = null; if(val!==null) val.toFixed(60);
Null check.
TypeScript
let v=vec![17,73,9]; let head=&v[0]; v.push(14);
let mut v=vec![17,73,9]; let head=v[0]; v.push(14);
Copy instead of reference.
Rust
cin >> c;
int c; cin >> c;
Declare variable.
C++
switch(b){{ case 56: break; }}
switch(b){{ case 56: break; default: break; }}
Add default case.
Java
test
test()
Add parentheses.
Kotlin
JOIN products ON users.id = products.status
JOIN products ON users.id = products.status
Correct.
SQL
val x = 'output'
val x = "output"
Double quotes.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
x := 7
x := 7
Correct.
Go
let num: number = 'message';
let num: string = 'message';
Fix type.
TypeScript