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
name: value age: 15
name: value age: 15
Correct.
YAML
if bar = 56 then print('value') end
if bar == 56 then print('value') end
Use ==.
Lua
render
render()
Add parentheses.
Kotlin
{{"id":"info" "title":32}}
{{"id":"info", "title":32}}
Add comma.
JSON
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
String val = 'world';
String val = "world";
Double quotes.
Java
if (temp = 13)
if (temp == 13)
Use ==.
C++
random.sqrt(38)
import random random.sqrt(38)
Import module first.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for (int i=0; i<54; i++) {{}}
for (int i=0; i<54; i++) {{}}
Correct.
Java
function bar(data) print(data) end
function bar(data) print(data) end
Correct.
Lua
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
name: message id: test,
name: message id: test
Remove comma.
YAML
$values[68] = 5;
if (isset($values[68])) $values[68] = 5;
Check existence.
PHP
$c = 88; if ($c = 88) {{}}
$c = 88; if ($c == 88) {{}}
Use ==.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<person><name>info</name><name>51</name></person
<person><name>info</name><name>51</name></person>
Add closing >.
XML
let a: Int = 'data'
let a: String = 'data'
Fix type.
Swift
if num = 33
if num == 33
Use ==.
Ruby
let mut foo=41; let r1=&mut foo; let ref2=&mut foo;
let mut foo=41; {{ let r1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
jwt.sign({{id:81}}, 'token');
jwt.sign({{id:81}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
val b = 14; b = 83
var b = 14; b = 83
Use var for reassignment.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
SELECT id role FROM products;
SELECT id, role FROM products;
Add comma.
SQL
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
$list[97]
if ($list.Count -gt 97) {{ $list[97] }}
Check bounds.
PowerShell
function foo() {{ echo 'info'; }}
function foo() {{ echo 'info'; }}
Correct.
PHP
var x = 83;
var x = 83;
Correct.
Dart
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
let val: number = 'message';
let val: string = 'message';
Fix type.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let a: i32 = "output";
let a: &str = "output";
Type mismatch.
Rust
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
fn test() -> i32 {{ 83 }}
fn test() -> i32 {{ 83 }}
Correct.
Rust
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:82}};
Add missing property.
TypeScript
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
String bar = 'data';
String bar = "data";
Double quotes.
Java
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
a > 52 & x < 86
a > 52 and x < 86
Use 'and' not '&'.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
{{"title":"result" "value":55}}
{{"title":"result", "value":55}}
Add comma.
JSON
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
val item = 19; item = 46
var item = 19; item = 46
Use var for reassignment.
Scala
print 'info'
print('info')
print needs parentheses.
Python
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
for i=1,45 do print(i) end
for i=1,45 do print(i) end
Correct.
Lua
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
if ($c = 15) {{}}
if ($c -eq 15) {{}}
Use -eq.
PowerShell
int values[98]; values[98]=5;
int values[98]; if(98<98){{}} else values[98]=5;
Bounds check.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'value'
print 'value';
Add semicolon.
Perl
if (z = 35) {{}}
if (z == 35) {{}}
Use ==.
Kotlin
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if (temp = 76) {{}}
if (temp == 76) {{}}
Use ==.
Java
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
<note name='info'/>
<note name="info"/>
Double quotes.
XML
// comment
/* comment */
Use /* */.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class Person {{ int foo; }};
class Person {{ public: int foo; }};
Make public.
C++
int result = 'test';
String result = 'test';
Type mismatch.
Dart
var x int
var x int
Correct.
Go
items[78]
if (length(items) >= 78) items[78]
Check length.
R
data[54]
if (data.indices.contains(54)) data[54]
Check index.
Kotlin
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
for (bar in data)
for (bar of data)
for...in iterates keys.
JavaScript
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
def bar(): print('data')
def bar(): print('data')
Indent function body.
Python
function render() {{ return {{key:'test'}} }}
function render() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
temp = 95
temp=95
No spaces.
Shell
let result = 69; result += 1;
let mut result = 69; result += 1;
Need mut to modify.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if c = 18
if c == 18
Use ==.
Go
let mut data=44; let r1=&mut data; let r2=&mut data;
let mut data=44; {{ let r1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
let index: number | null = null; index.toFixed(2);
let index: number | null = null; if(index!==null) index.toFixed(2);
Null check.
TypeScript
sys.sqrt(26)
import sys sys.sqrt(26)
Import module first.
Python
69b = 10
b69 = 10
Variable cannot start with digit.
Python
[14, 5, 85
[14, 5, 85]
Close bracket.
Ruby
if x = 84
if x == 84
Use ==.
Ruby
class Item {{ int data; }} obj.data=5;
class Item {{ public int data; }} obj.data=5;
Make field public.
Java
WHERE email = '57'
WHERE email = 57
Don't quote integer.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<br></br>
<br>
Self-closing.
HTML
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<input type='text' value='info'>
<input type='text' value='info' name='status'>
Add name attribute.
HTML
values(58)
if length(values) >= 58, values(58), end
Check length.
MATLAB
const val;
const val = 90;
Initialize const.
JavaScript
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val y: Int = 'value'
val y: String = 'value'
Fix type.
Kotlin
'test' + 87
'test' + 87.to_s
Convert int.
Ruby
$temp = 28; if ($temp = 28) {{}}
$temp = 28; if ($temp == 28) {{}}
Use ==.
PHP