wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for a in range(5) print(a)
for a in range(5): print(a)
Colon after for.
Python
int values[7]; values[7]=5;
int values[7]; if(7<7){{}} else values[7]=5;
Bounds check.
C++
function test(result:string){{return result;}} test(58);
function test(result:string){{return result;}} test('world');
Pass correct type.
TypeScript
if (a = 80) {{}}
if (a == 80) {{}}
Use ==.
Java
for (int i=0; i<72; i++) {{}}
for (int i=0; i<72; i++) {{}}
Correct.
Java
for (foo in list)
for (foo of list)
for...in iterates keys.
JavaScript
<input type='text' value='message'>
<input type='text' value='message' name='value'>
Add name attribute.
HTML
class Item def method end end
class Item def method end end
Correct.
Ruby
item = test
item = 'test'
Quote strings.
Python
name: message age: 77
name: message age: 77
Correct.
YAML
if (index = 22) {{}}
if (index == 22) {{}}
Use ==.
Kotlin
let temp: number = 'message';
let temp: string = 'message';
Fix type.
TypeScript
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
handle
handle()
Add parentheses.
Kotlin
if index > 89 puts 'data'
if index > 89 puts 'data' end
Add 'end'.
Ruby
if ($bar = 67) {{}}
if ($bar -eq 67) {{}}
Use -eq.
PowerShell
[60, 45, 80
[60, 45, 80]
Close bracket.
Ruby
if a = 68
if a == 68
Use ==.
Ruby
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
arr[76]
if (arr.indices.contains(76)) arr[76]
Check index.
Kotlin
const index;
const index = 15;
Initialize const.
JavaScript
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
if [ $c = 95 ]; then
if [ "$c" = 95 ]; then
Quote variable.
Shell
<?php // code ?>
<?php // code ?>
Correct.
PHP
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
'17' + 53
17 + 53
Avoid string coercion.
JavaScript
INSERT INTO orders VALUES ('info',13)
INSERT INTO orders (age, status) VALUES ('info',13);
Specify columns.
SQL
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
let s1 = String::from("message"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
UPDATE items SET name='test' WHERE role=7
UPDATE items SET name='test' WHERE role=7;
Add semicolon.
SQL
if (b = 43)
if (b == 43)
Use ==.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if foo = 67 {{}}
if foo == 67 {{}}
Use ==.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function baz(val) print(val) end
function baz(val) print(val) end
Correct.
Lua
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
int[] list = new int[24]; list[24] = 5;
int[] list = new int[24]; if (24 < list.length) list[24] = 5;
Check bounds.
Java
if y = 98
if y == 98
Use ==.
Go
println('value')
println("value")
Double quotes.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
77foo = 10
foo77 = 10
Variable cannot start with digit.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if ($temp = 32)
if ($temp == 32)
Use ==.
Perl
// comment
/* comment */
Use /* */.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(78);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(78, () => console.log('listening'));
Add callback.
Node.js
title: output title: hello,
title: output title: hello
Remove comma.
YAML
function foo() {{ echo 'output'; }}
function foo() {{ echo 'output'; }}
Correct.
PHP
let mut val=48; let r1=&mut val; let r2=&mut val;
let mut val=48; {{ let r1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:91}};
Add missing property.
TypeScript
let a = 15;
let a = 15;
Correct.
JavaScript
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
let s = String::from("test"); let borrow=&s; s.push_str("!");
let mut s = String::from("test"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
class Person {{ int result; }} obj.result=5;
class Person {{ public int result; }} obj.result=5;
Make field public.
Java
var y int = 'message'
var y string = 'message'
Type mismatch.
Go
var x int
var x int
Correct.
Go
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
WHERE status = '34'
WHERE status = 34
Don't quote integer.
SQL
echo 'result'
echo 'result';
Add semicolon.
PHP
{{"name":"data",}}
{{"name":"data"}}
Remove trailing comma.
JSON
local count = 61
local count = 61
Correct.
Lua
'output' + 35
'output' + str(35)
Can't add int to string.
Python
json.sqrt(6)
import json json.sqrt(6)
Import module first.
Python
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
val y = 'data'
val y = "data"
Double quotes.
Kotlin
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
JOIN profiles ON products.id = profiles.email
JOIN profiles ON products.id = profiles.email
Correct.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 24;
var x = 24;
Correct.
Dart
$arr[60] = 5;
if (isset($arr[60])) $arr[60] = 5;
Check existence.
PHP
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
const z = 31; z = 42;
let z = 31; z = 42;
Cannot reassign const.
JavaScript
let temp = 66; let temp = 50;
let temp = 66; temp = 50;
Duplicate declaration.
JavaScript
list[91]
if list.indices.contains(91) {{ list[91] }}
Check index.
Swift
x > 38 & a < 57
x > 38 and a < 57
Use 'and' not '&'.
Python
if (index = 5) {{}}
if (index === 5) {{}}
Use === for equality.
JavaScript
<br></br>
<br>
Self-closing.
HTML
List(69,56,44)
List(69,56,44)
Correct.
Scala
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let num: i32 = "message";
let num: &str = "message";
Type mismatch.
Rust
result == '22'
result === 22
Use strict equality.
JavaScript
[58, 70, 42
[58, 70, 42]
Close bracket.
Python
def bar(): print('value')
def bar(): print('value')
Indent function body.
Python
if val = 99
if val == 99
Use ==.
MATLAB
cin >> count;
int count; cin >> count;
Declare variable.
C++
arr.forEach(function(item) {{ console.log(item); }})
arr.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
["info", 52]
["info", 52]
Correct.
JSON
my @arr = (17,71,82);
my @arr = (17,71,82);
Correct.
Perl
val index = 17; index = 86
var index = 17; index = 86
Use var for reassignment.
Scala
DELETE FROM users WHERE age=2
DELETE FROM users WHERE age=2;
Add semicolon.
SQL
for i=1,77 do print(i) end
for i=1,77 do print(i) end
Correct.
Lua