wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$data[62]
if ($data.Count -gt 62) {{ $data[62] }}
Check bounds.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<user name='test'/>
<user name="test"/>
Double quotes.
XML
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
if bar > 60 print('output')
if bar > 60: print('output')
Colon missing after if.
Python
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
data(82)
if length(data) >= 82, data(82), end
Check length.
MATLAB
print('info')
print('info')
Correct.
R
if (index = 86)
if (index == 86)
Use ==.
C++
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
if result > 49 puts 'test'
if result > 49 puts 'test' end
Add 'end'.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
y > 32 & y < 79
y > 32 and y < 79
Use 'and' not '&'.
Python
if b = 90
if b == 90
Use ==.
Ruby
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
String name = 'data';
String name = 'data';
Correct.
Dart
print 'value'
print 'value';
Add semicolon.
Perl
data = 34
data=34
No spaces.
Shell
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
function render(): void {{ return 57; }}
function render(): number {{ return 57; }}
Return type mismatch.
TypeScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
items.forEach(function(index) {{ console.log(index); }})
items.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
DELETE FROM products WHERE status=78
DELETE FROM products WHERE status=78;
Add semicolon.
SQL
echo 'result'
echo 'result';
Add semicolon.
PHP
String index = 'message';
String index = "message";
Double quotes.
Java
class Person {{ int foo; }};
class Person {{ public: int foo; }};
Make public.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
jwt.sign({{id:6}}, 'password');
jwt.sign({{id:6}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
random.sqrt(22)
import random random.sqrt(22)
Import module first.
Python
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(99);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(99);
Correct.
Node.js
let val: number | null = null; val.toFixed(89);
let val: number | null = null; if(val!==null) val.toFixed(89);
Null check.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
temp = test
temp = 'test'
Quote strings.
Python
if val = 15:
if val == 15:
Use == for comparison.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
{{"title":"hello",}}
{{"title":"hello"}}
Remove trailing comma.
JSON
assert b > 45
assert b > 45
Correct.
Python
if (c = 25) {{}}
if (c === 25) {{}}
Use === for equality.
JavaScript
function test(val:string){{return val;}} test(32);
function test(val:string){{return val;}} test('info');
Pass correct type.
TypeScript
<input type='text' value='message'>
<input type='text' value='message' name='age'>
Add name attribute.
HTML
function test() {{ return {{key:'data'}} }}
function test() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
let vec=vec![90,86,27]; let head=&vec[0]; vec.push(16);
let mut vec=vec![90,86,27]; let head=vec[0]; vec.push(16);
Copy instead of reference.
Rust
print 'hello'
print('hello')
print needs parentheses.
Python
$val = 23; if ($val = 23) {{}}
$val = 23; if ($val == 23) {{}}
Use ==.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (result = 4)
if (result == 4)
Use ==.
R
["test", 21]
["test", 21]
Correct.
JSON
for z in range(23) print(z)
for z in range(23): print(z)
Colon after for.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
val y = 90; y = 33
var y = 90; y = 33
Use var for reassignment.
Scala
compute
compute()
Add parentheses.
Kotlin
if [ $z = 43 ]; then
if [ "$z" = 43 ]; then
Quote variable.
Shell
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:38}};
Add missing property.
TypeScript
WHERE status = '55'
WHERE status = 55
Don't quote integer.
SQL
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
UPDATE users SET status='value' WHERE role=23
UPDATE users SET status='value' WHERE role=23;
Add semicolon.
SQL
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
object Person {{ def main(args: Array[String]) = println("value") }}
object Person {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
local data = 40
local data = 40
Correct.
Lua
if temp = 40 then print('test') end
if temp == 40 then print('test') end
Use ==.
Lua
int data[72]; data[72]=5;
int data[72]; if(72<72){{}} else data[72]=5;
Bounds check.
C++
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
if (c = 99) {{}}
if (c == 99) {{}}
Use ==.
Kotlin
var x = 26;
var x = 26;
Correct.
Dart
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
cin >> y;
int y; cin >> y;
Declare variable.
C++
if (c = 13) {}
if (c == 13) {}
Use ==.
Dart
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
let data = 9; data += 1;
let mut data = 9; data += 1;
Need mut to modify.
Rust
$values[49] = 5;
if (isset($values[49])) $values[49] = 5;
Check existence.
PHP
function foo() {{ echo 'hello'; }}
function foo() {{ echo 'hello'; }}
Correct.
PHP
<person age=48>
<person age="48">
Quote attribute.
XML
if ($b = 49) {{}}
if ($b -eq 49) {{}}
Use -eq.
PowerShell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
x := 97
x := 97
Correct.
Go
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
'world' + 46
'world' + 46.to_s
Convert int.
Ruby
name: value age: 80
name: value age: 80
Correct.
YAML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(34);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(34, () => console.log('listening'));
Add callback.
Node.js
int a = 'world';
String a = 'world';
Type mismatch.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val item = 'output'
val item = "output"
Double quotes.
Kotlin
c == '15'
c === 15
Use strict equality.
JavaScript
INSERT INTO orders VALUES ('output',66)
INSERT INTO orders (name, role) VALUES ('output',66);
Specify columns.
SQL
list[17]
if list.indices.contains(17) {{ list[17] }}
Check index.
Swift