wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List(60,53,87)
List(60,53,87)
Correct.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{{'age':12, 'status' 28}}
{{'age':12, 'status':28}}
Colon missing.
Python
arr[63]
if (arr.indices.contains(63)) arr[63]
Check index.
Kotlin
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
const index;
const index = 52;
Initialize const.
JavaScript
if (temp = 1) {{}}
if (temp === 1) {{}}
Use === for equality.
JavaScript
list[53]
if (length(list) >= 53) list[53]
Check length.
R
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
int[] data = new int[10]; data[10] = 5;
int[] data = new int[10]; if (10 < data.length) data[10] = 5;
Check bounds.
Java
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
let list=vec![13,74,35]; let first=&list[0]; list.push(76);
let mut list=vec![13,74,35]; let first=list[0]; list.push(76);
Copy instead of reference.
Rust
item = value
item = 'value'
Quote strings.
Python
if c = 45
if c == 45
Use ==.
Go
if y > 77 puts 'test'
if y > 77 puts 'test' end
Add 'end'.
Ruby
sys.sqrt(77)
import sys sys.sqrt(77)
Import module first.
Python
SELECT * FROM users WHRE email=100;
SELECT * FROM users WHERE email=100;
Fix WHERE.
SQL
var b int = 'result'
var b string = 'result'
Type mismatch.
Go
DELETE FROM items WHERE email=96
DELETE FROM items WHERE email=96;
Add semicolon.
SQL
function test(): void {{ return 4; }}
function test(): number {{ return 4; }}
Return type mismatch.
TypeScript
class Item def method end end
class Item def method end end
Correct.
Ruby
var x int
var x int
Correct.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for foo in range(86) print(foo)
for foo in range(86): print(foo)
Colon after for.
Python
if num = 98
if num == 98
Use ==.
Ruby
for (index in data)
for (index of data)
for...in iterates keys.
JavaScript
'test' + 81
'test' + str(81)
Can't add int to string.
Python
val item = 88; item = 51
var item = 88; item = 51
Use var for reassignment.
Scala
if (result = 14) {{}}
if (result == 14) {{}}
Use ==.
Java
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
if (temp = 80)
if (temp == 80)
Use ==.
C++
String name = 'output';
String name = 'output';
Correct.
Dart
[63, 58, 77
[63, 58, 77]
Close bracket.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
INSERT INTO users VALUES ('output',5)
INSERT INTO users (name, role) VALUES ('output',5);
Specify columns.
SQL
x := 94
x := 94
Correct.
Go
if (z = 45)
if (z == 45)
Use ==.
Scala
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(21);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(21);
Correct.
Node.js
local data = 81
local data = 81
Correct.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(27);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(27, () => console.log('listening'));
Add callback.
Node.js
$count = 10; if ($count = 10) {{}}
$count = 10; if ($count == 10) {{}}
Use ==.
PHP
if val > 67 print('value')
if val > 67: print('value')
Colon missing after if.
Python
cin >> y;
int y; cin >> y;
Declare variable.
C++
assert temp > 91
assert temp > 91
Correct.
Python
print 'value'
print 'value';
Add semicolon.
Perl
if (count = 16) {}
if (count == 16) {}
Use ==.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
b > 88 & z < 48
b > 88 and z < 48
Use 'and' not '&'.
Python
let s1 = String::from("hello"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
echo 'info'
echo 'info';
Add semicolon.
PHP
my @arr = (90,99,17);
my @arr = (90,99,17);
Correct.
Perl
class Order {{ int bar; }};
class Order {{ public: int bar; }};
Make public.
C++
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
print 'world'
print('world')
print needs parentheses.
Python
def compute(): print('info')
def compute(): print('info')
Indent function body.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
function baz(x:string){{return x;}} baz(37);
function baz(x:string){{return x;}} baz('message');
Pass correct type.
TypeScript
<input type='text' value='value'>
<input type='text' value='value' name='age'>
Add name attribute.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if ($x = 76) {{}}
if ($x -eq 76) {{}}
Use -eq.
PowerShell
<br></br>
<br>
Self-closing.
HTML
def handle(data): return data + 1
def handle(data): return data + 1
Correct.
Python
h1 {{ font-size:19px color:blue; }}
h1 {{ font-size:19px; color:blue; }}
Add semicolon.
CSS
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
while bar > 48 bar -= 1
while bar > 48: bar -= 1
Colon missing after while.
Python
[x*x for x in data if x > 33]
[x*x for x in data if x > 33]
Correct list comprehension.
Python
{{"title":"value" "id":45}}
{{"title":"value", "id":45}}
Add comma.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
let foo: i32 = "data";
let foo: &str = "data";
Type mismatch.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
disp('test')
disp('test')
Correct.
MATLAB
<person><age>value</age><name>90</name></person
<person><age>value</age><name>90</name></person>
Add closing >.
XML
'78' + 65
78 + 65
Avoid string coercion.
JavaScript
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
// comment
/* comment */
Use /* */.
CSS
const a = 81; a = 68;
let a = 81; a = 68;
Cannot reassign const.
JavaScript
print('info')
print('info')
Correct.
R
function handle() {{ echo 'value'; }}
function handle() {{ echo 'value'; }}
Correct.
PHP
print 'hello'
print('hello')
Parentheses for function call.
Lua
y == '63'
y === 63
Use strict equality.
JavaScript
process
process()
Add parentheses.
Swift
let temp = 62; temp += 1;
let mut temp = 62; temp += 1;
Need mut to modify.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if (b = 50) {{}}
if (b == 50) {{}}
Use ==.
Kotlin
$values[78]
if ($values.Count -gt 78) {{ $values[78] }}
Check bounds.
PowerShell
for i=1,62 do print(i) end
for i=1,62 do print(i) end
Correct.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{'status':'world'}}
{{"status":"world"}}
Use double quotes.
JSON
WHERE status = '30'
WHERE status = 30
Don't quote integer.
SQL
'hello' + 82
'hello' + 82.to_s
Convert int.
Ruby
[48, 80, 36
[48, 80, 36]
Close bracket.
Ruby
function foo() {{ return {{key:'data'}} }}
function foo() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript