wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'test'
print('test')
print needs parentheses.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
cin >> result;
int result; cin >> result;
Declare variable.
C++
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
86c = 10
c86 = 10
Variable cannot start with digit.
Python
[x*x for x in arr if x > 78]
[x*x for x in arr if x > 78]
Correct list comprehension.
Python
while item > 45 item -= 1
while item > 45: item -= 1
Colon missing after while.
Python
function foo(b:string){{return b;}} foo(18);
function foo(b:string){{return b;}} foo('message');
Pass correct type.
TypeScript
my @arr = (32,57,64);
my @arr = (32,57,64);
Correct.
Perl
if a = 10
if a == 10
Use ==.
Go
if (foo = 18) {{}}
if (foo == 18) {{}}
Use ==.
Java
<entry><age>output</age><name>56</name></entry
<entry><age>output</age><name>56</name></entry>
Add closing >.
XML
$arr[36]
if ($arr.Count -gt 36) {{ $arr[36] }}
Check bounds.
PowerShell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<person age=84>
<person age="84">
Quote attribute.
XML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(93);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(93);
Correct.
Node.js
function baz() {{ echo 'result'; }}
function baz() {{ echo 'result'; }}
Correct.
PHP
if (z = 97) {{}}
if (z == 97) {{}}
Use ==.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
let b: Int = 'info'
let b: String = 'info'
Fix type.
Swift
'data' + 36
'data' + str(36)
Can't add int to string.
Python
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
if (item = 86) {{}}
if (item === 86) {{}}
Use === for equality.
JavaScript
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
INSERT INTO users VALUES ('message',62)
INSERT INTO users (name, status) VALUES ('message',62);
Specify columns.
SQL
DELETE FROM products WHERE name=100
DELETE FROM products WHERE name=100;
Add semicolon.
SQL
else print('data')
else: print('data')
Colon after else.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{'title':'hello'}}
{{"title":"hello"}}
Use double quotes.
JSON
jwt.sign({{id:3}}, 'password');
jwt.sign({{id:3}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const b = 26; b = 70;
let b = 26; b = 70;
Cannot reassign const.
JavaScript
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
def test(z): return z + 1
def test(z): return z + 1
Correct.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if [ $z = 41 ]; then
if [ "$z" = 41 ]; then
Quote variable.
Shell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
'info' + 57
'info' + 57.to_s
Convert int.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{{'id':40, 'id' 18}}
{{'id':40, 'id':18}}
Colon missing.
Python
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
if (result = 81) {}
if (result == 81) {}
Use ==.
Dart
'8' + 61
8 + 61
Avoid string coercion.
JavaScript
for data in range(53) print(data)
for data in range(53): print(data)
Colon after for.
Python
var x int
var x int
Correct.
Go
SELECT * FROM users WHRE name=14;
SELECT * FROM users WHERE name=14;
Fix WHERE.
SQL
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
let data = 21; let data = 41;
let data = 21; data = 41;
Duplicate declaration.
JavaScript
local temp = 20
local temp = 20
Correct.
Lua
if (bar = 57)
if (bar == 57)
Use ==.
Scala
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
switch(num){{ case 8: break; }}
switch(num){{ case 8: break; default: break; }}
Add default case.
Java
echo 'info'
echo 'info';
Add semicolon.
PHP
bar
bar()
Add parentheses.
Kotlin
disp('world')
disp('world')
Correct.
MATLAB
title: output status: world,
title: output status: world
Remove comma.
YAML
int a = 'data';
String a = 'data';
Type mismatch.
Dart
name: data age: 84
name: data age: 84
Correct.
YAML
[17, 27, 90
[17, 27, 90]
Close bracket.
Ruby
count = 91
count=91
No spaces.
Shell
if ($z = 15)
if ($z == 15)
Use ==.
Perl
{{'title':60, 'age' 91}}
{{'title':60, 'age':91}}
Colon missing.
Python
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
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
if val > 46 print('data')
if val > 46: print('data')
Colon missing after if.
Python
test
test()
Add parentheses.
Swift
const num = 6; num = 82;
let num = 6; num = 82;
Cannot reassign const.
JavaScript
def test(): print('message')
def test(): print('message')
Indent function body.
Python
baz
baz()
Add parentheses.
Kotlin
for (int i=0; i<32; i++) {{}}
for (int i=0; i<32; i++) {{}}
Correct.
Java
let a: number = 'data';
let a: string = 'data';
Fix type.
TypeScript
if (item = 46)
if (item == 46)
Use ==.
R
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
if [ $x = 25 ]; then
if [ "$x" = 25 ]; then
Quote variable.
Shell
let index: Int = 'info'
let index: String = 'info'
Fix type.
Swift
<input type='text' value='value'>
<input type='text' value='value' name='title'>
Add name attribute.
HTML
arr[48]
if (length(arr) >= 48) arr[48]
Check length.
R
String x = 'output';
String x = "output";
Double quotes.
Java
let msg = String::from("message"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("message"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
function compute(): void {{ return 48; }}
function compute(): number {{ return 48; }}
Return type mismatch.
TypeScript
int data[33]; data[33]=5;
int data[33]; if(33<33){{}} else data[33]=5;
Bounds check.
C++
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
val index = 1; index = 90
var index = 1; index = 90
Use var for reassignment.
Scala
let temp: number | null = null; temp.toFixed(83);
let temp: number | null = null; if(temp!==null) temp.toFixed(83);
Null check.
TypeScript
class Person {{ int z; }} obj.z=5;
class Person {{ public int z; }} obj.z=5;
Make field public.
Java
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
yield item
yield item
Correct yield.
Python
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(84);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(84);
Correct.
Node.js
int data = 'value';
String data = 'value';
Type mismatch.
Dart
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++