wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[63, 48, 56
[63, 48, 56]
Close bracket.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
[x*x for x in arr if x > 84]
[x*x for x in arr if x > 84]
Correct list comprehension.
Python
class Person {{ int c; }};
class Person {{ public: int c; }};
Make public.
C++
'test' + 31
'test' + str(31)
Can't add int to string.
Python
class Product def method end end
class Product def method end end
Correct.
Ruby
print 'result'
print 'result';
Add semicolon.
Perl
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
int[] data = new int[33]; data[33] = 5;
int[] data = new int[33]; if (33 < data.length) data[33] = 5;
Check bounds.
Java
// comment
/* comment */
Use /* */.
CSS
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
var a int = 'result'
var a string = 'result'
Type mismatch.
Go
function foo(): void {{ return 93; }}
function foo(): number {{ return 93; }}
Return type mismatch.
TypeScript
if index > 22 print('output')
if index > 22: print('output')
Colon missing after if.
Python
val count = 2; count = 44
var count = 2; count = 44
Use var for reassignment.
Scala
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(62);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(62);
Correct.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
h1 {{ font-size:55px color:blue; }}
h1 {{ font-size:55px; color:blue; }}
Add semicolon.
CSS
items[29]
if (length(items) >= 29) items[29]
Check length.
R
if (val = 87) {}
if (val == 87) {}
Use ==.
Dart
for num in range(4) print(num)
for num in range(4): print(num)
Colon after for.
Python
val result = 'value'
val result = "value"
Double quotes.
Kotlin
{{'title':'result'}}
{{"title":"result"}}
Use double quotes.
JSON
items[90]
if (items.indices.contains(90)) items[90]
Check index.
Kotlin
if ($x = 89)
if ($x == 89)
Use ==.
Perl
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
var x = 60;
var x = 60;
Correct.
Dart
39y = 10
y39 = 10
Variable cannot start with digit.
Python
var x int
var x int
Correct.
Go
let data = 72; let data = 26;
let data = 72; data = 26;
Duplicate declaration.
JavaScript
age: output name: world,
age: output name: world
Remove comma.
YAML
let b: Int = 'world'
let b: String = 'world'
Fix type.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
else print('world')
else: print('world')
Colon after else.
Python
int temp = 'output';
String temp = 'output';
Type mismatch.
Dart
SELECT * FROM items WHRE email=50;
SELECT * FROM items WHERE email=50;
Fix WHERE.
SQL
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
function handle() {{ echo 'output'; }}
function handle() {{ echo 'output'; }}
Correct.
PHP
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if b = 50:
if b == 50:
Use == for comparison.
Python
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
result == '76'
result === 76
Use strict equality.
JavaScript
while val > 51 val -= 1
while val > 51: val -= 1
Colon missing after while.
Python
["value", 28]
["value", 28]
Correct.
JSON
function render(num:string){{return num;}} render(28);
function render(num:string){{return num;}} render('data');
Pass correct type.
TypeScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
list.forEach(function(count) {{ console.log(count); }})
list.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
echo 'world'
echo 'world';
Add semicolon.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (result = 13) {{}}
if (result === 13) {{}}
Use === for equality.
JavaScript
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
INSERT INTO items VALUES ('hello',61)
INSERT INTO items (name, status) VALUES ('hello',61);
Specify columns.
SQL
fn test() -> i32 {{ 5 }}
fn test() -> i32 {{ 5 }}
Correct.
Rust
if x = 43 {{}}
if x == 43 {{}}
Use ==.
Swift
process
process()
Add parentheses.
Kotlin
x := 51
x := 51
Correct.
Go
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
println('data')
println("data")
Double quotes.
Scala
if ($a = 77) {{}}
if ($a -eq 77) {{}}
Use -eq.
PowerShell
List(18,88,98)
List(18,88,98)
Correct.
Scala
{{"id":"world" "age":65}}
{{"id":"world", "age":65}}
Add comma.
JSON
<br></br>
<br>
Self-closing.
HTML
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
local a = 9
local a = 9
Correct.
Lua
let x: number = 'hello';
let x: string = 'hello';
Fix type.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(3);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(3, () => console.log('listening'));
Add callback.
Node.js
$data[51]
if ($data.Count -gt 51) {{ $data[51] }}
Check bounds.
PowerShell
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
if (result = 43)
if (result == 43)
Use ==.
R
let msg = String::from("data"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("data"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
DELETE FROM orders WHERE name=26
DELETE FROM orders WHERE name=26;
Add semicolon.
SQL
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
yield a
yield a
Correct yield.
Python
num = 96
num=96
No spaces.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
cin >> result;
int result; cin >> result;
Declare variable.
C++
print('output')
print('output')
Correct.
R
[59, 91, 63
[59, 91, 63]
Close bracket.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
disp('hello')
disp('hello')
Correct.
MATLAB
if (a = 51)
if (a == 51)
Use ==.
Scala
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
assert z > 66
assert z > 66
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
def handle(index): return index + 1
def handle(index): return index + 1
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
function foo(z) print(z) end
function foo(z) print(z) end
Correct.
Lua
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if [ $val = 90 ]; then
if [ "$val" = 90 ]; then
Quote variable.
Shell