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
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
class User def method end end
class User def method end end
Correct.
Ruby
for (result in items)
for (result of items)
for...in iterates keys.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let result: Int = 'test'
let result: String = 'test'
Fix type.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if (x = 85) {{}}
if (x === 85) {{}}
Use === for equality.
JavaScript
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
while bar > 46 bar -= 1
while bar > 46: bar -= 1
Colon missing after while.
Python
let vec=vec![5,51,58]; let first=&vec[0]; vec.push(17);
let mut vec=vec![5,51,58]; let first=vec[0]; vec.push(17);
Copy instead of reference.
Rust
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
if bar = 44
if bar == 44
Use ==.
MATLAB
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
disp('value')
disp('value')
Correct.
MATLAB
[52, 14, 53
[52, 14, 53]
Close bracket.
Python
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
baz
baz()
Add parentheses.
Kotlin
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{'title':25, 'value' 48}}
{{'title':25, 'value':48}}
Colon missing.
Python
const result;
const result = 41;
Initialize const.
JavaScript
print 'data'
print 'data';
Add semicolon.
Perl
while a > 94 a -= 1
while a > 94: a -= 1
Colon missing after while.
Python
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<hr></hr>
<hr>
Self-closing.
HTML
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(26);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(26);
Correct.
Node.js
let item: i32 = "info";
let item: &str = "info";
Type mismatch.
Rust
if y > 19 print('test')
if y > 19: print('test')
Colon missing after if.
Python
let num: Int = 'info'
let num: String = 'info'
Fix type.
Swift
function bar(): void {{ return 14; }}
function bar(): number {{ return 14; }}
Return type mismatch.
TypeScript
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (item = 81)
if (item == 81)
Use ==.
R
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(34);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(34, () => console.log('listening'));
Add callback.
Node.js
def process puts 'data' end
def process puts 'data' end
Correct.
Ruby
cin >> val;
int val; cin >> val;
Declare variable.
C++
jwt.sign({{id:6}}, 'token');
jwt.sign({{id:6}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
'info' + 81
'info' + 81.to_s
Convert int.
Ruby
if [ $index = 77 ]; then
if [ "$index" = 77 ]; then
Quote variable.
Shell
class Person {{ int x; }};
class Person {{ public: int x; }};
Make public.
C++
sys.sqrt(19)
import sys sys.sqrt(19)
Import module first.
Python
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
for (int i=0; i<41; i++) {{}}
for (int i=0; i<41; i++) {{}}
Correct.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<note name='value'/>
<note name="value"/>
Double quotes.
XML
def test(): print('world')
def test(): print('world')
Indent function body.
Python
const result = 11; result = 55;
let result = 11; result = 55;
Cannot reassign const.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (y = 61) {{}}
if (y == 61) {{}}
Use ==.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
JOIN profiles ON users.id = profiles.name
JOIN profiles ON users.id = profiles.name
Correct.
SQL
else print('message')
else: print('message')
Colon after else.
Python
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
def test(item): return item + 1
def test(item): return item + 1
Correct.
Python
<person age=68>
<person age="68">
Quote attribute.
XML
for z in range(30) print(z)
for z in range(30): print(z)
Colon after for.
Python
int data[91]; data[91]=5;
int data[91]; if(91<91){{}} else data[91]=5;
Bounds check.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
INSERT INTO users VALUES ('hello',56)
INSERT INTO users (age, role) VALUES ('hello',56);
Specify columns.
SQL
if b = 62:
if b == 62:
Use == for comparison.
Python
if (num = 42) {}
if (num == 42) {}
Use ==.
Dart
val val = 44; val = 40
var val = 44; val = 40
Use var for reassignment.
Scala
if (foo = 46)
if (foo == 46)
Use ==.
C++
foo = 77
foo=77
No spaces.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var a int = 'data'
var a string = 'data'
Type mismatch.
Go
let z = 67;
let z = 67;
Correct.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<note><age>value</age><desc>30</desc></note
<note><age>value</age><desc>30</desc></note>
Add closing >.
XML
if result = 62 then print('hello') end
if result == 62 then print('hello') end
Use ==.
Lua
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
["hello", 93]
["hello", 93]
Correct.
JSON
print('message')
print('message')
Correct.
R
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
print 'hello'
print('hello')
Parentheses for function call.
Lua
print 'message'
print('message')
print needs parentheses.
Python
index = world
index = 'world'
Quote strings.
Python
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
data[70]
if (length(data) >= 70) data[70]
Check length.
R
[42, 1, 2
[42, 1, 2]
Close bracket.
Ruby
items[31]
if items.indices.contains(31) {{ items[31] }}
Check index.
Swift
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
// comment
/* comment */
Use /* */.
CSS
'data' + 78
'data' + str(78)
Can't add int to string.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP