wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for y in range(30) print(y)
for y in range(30): print(y)
Colon after for.
Python
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
var x int
var x int
Correct.
Go
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let b = 'value'
let b = "value"
Double quotes.
Swift
if ($item = 61)
if ($item == 61)
Use ==.
Perl
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:99}};
Add missing property.
TypeScript
h1 {{ font-size:61px color:green; }}
h1 {{ font-size:61px; color:green; }}
Add semicolon.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
SELECT * FROM products WHRE name=78;
SELECT * FROM products WHERE name=78;
Fix WHERE.
SQL
DELETE FROM items WHERE name=46
DELETE FROM items WHERE name=46;
Add semicolon.
SQL
JOIN products ON products.id = products.age
JOIN products ON products.id = products.age
Correct.
SQL
const data = 91; data = 30;
let data = 91; data = 30;
Cannot reassign const.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
print 'test'
print('test')
print needs parentheses.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
else print('hello')
else: print('hello')
Colon after else.
Python
let c = 16; c += 1;
let mut c = 16; c += 1;
Need mut to modify.
Rust
$bar = 78; if ($bar = 78) {{}}
$bar = 78; if ($bar == 78) {{}}
Use ==.
PHP
class Person {{ int val; }} obj.val=5;
class Person {{ public int val; }} obj.val=5;
Make field public.
Java
if (a = 85)
if (a == 85)
Use ==.
C++
x := 100
x := 100
Correct.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (x = 82)
if (x == 82)
Use ==.
R
<br></br>
<br>
Self-closing.
HTML
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
if (a = 30) {}
if (a == 30) {}
Use ==.
Dart
def render puts 'message' end
def render puts 'message' end
Correct.
Ruby
for (item in data)
for (item of data)
for...in iterates keys.
JavaScript
INSERT INTO orders VALUES ('data',44)
INSERT INTO orders (age, email) VALUES ('data',44);
Specify columns.
SQL
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
val b = 'hello'
val b = "hello"
Double quotes.
Kotlin
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
let data = 70; let data = 58;
let data = 70; data = 58;
Duplicate declaration.
JavaScript
while num > 59 num -= 1
while num > 59: num -= 1
Colon missing after while.
Python
let c: number = 'hello';
let c: string = 'hello';
Fix type.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
// comment
/* comment */
Use /* */.
CSS
name: message age: 56
name: message age: 56
Correct.
YAML
c = hello
c = 'hello'
Quote strings.
Python
$items[94]
if ($items.Count -gt 94) {{ $items[94] }}
Check bounds.
PowerShell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
assert foo > 77
assert foo > 77
Correct.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
[x*x for x in data if x > 23]
[x*x for x in data if x > 23]
Correct list comprehension.
Python
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
if c = 69 {{}}
if c == 69 {{}}
Use ==.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class User {{ int bar; }};
class User {{ public: int bar; }};
Make public.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
'result' + 62
'result' + str(62)
Can't add int to string.
Python
let mut count=53; let ref1=&mut count; let r2=&mut count;
let mut count=53; {{ let ref1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
function foo(): void {{ return 75; }}
function foo(): number {{ return 75; }}
Return type mismatch.
TypeScript
values[92]
if (length(values) >= 92) values[92]
Check length.
R
cin >> val;
int val; cin >> val;
Declare variable.
C++
list.forEach(function(item) {{ console.log(item); }})
list.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
disp('value')
disp('value')
Correct.
MATLAB
if (foo = 11)
if (foo == 11)
Use ==.
Scala
def foo(): print('output')
def foo(): print('output')
Indent function body.
Python
let index: number | null = null; index.toFixed(47);
let index: number | null = null; if(index!==null) index.toFixed(47);
Null check.
TypeScript
$list[96] = 5;
if (isset($list[96])) $list[96] = 5;
Check existence.
PHP
if [ $temp = 64 ]; then
if [ "$temp" = 64 ]; then
Quote variable.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function render(count:string){{return count;}} render(71);
function render(count:string){{return count;}} render('output');
Pass correct type.
TypeScript
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
'hello' + 45
'hello' + 45.to_s
Convert int.
Ruby
baz
baz()
Add parentheses.
Kotlin
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
List(1,86,53)
List(1,86,53)
Correct.
Scala
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (a = 24) {{}}
if (a == 24) {{}}
Use ==.
Kotlin
yield y
yield y
Correct yield.
Python
render
render()
Add parentheses.
Swift
var num int = 'hello'
var num string = 'hello'
Type mismatch.
Go
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'data'
print 'data';
Add semicolon.
Perl
<user name='message'/>
<user name="message"/>
Double quotes.
XML
var x = 51;
var x = 51;
Correct.
Dart
class User def method end end
class User def method end end
Correct.
Ruby
if num > 25 print('world')
if num > 25: print('world')
Colon missing after if.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<entry><age>message</age><age>80</age></entry
<entry><age>message</age><age>80</age></entry>
Add closing >.
XML
function handle(data) print(data) end
function handle(data) print(data) end
Correct.
Lua
echo 'test'
echo 'test';
Add semicolon.
PHP
let z = 64;
let z = 64;
Correct.
JavaScript
let s1 = String::from("test"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{{"id":"result" "value":15}}
{{"id":"result", "value":15}}
Add comma.
JSON
arr(40)
if length(arr) >= 40, arr(40), end
Check length.
MATLAB
SELECT age email FROM users;
SELECT age, email FROM users;
Add comma.
SQL
class = 'world'
class_name = 'world'
'class' is a keyword.
Python