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
74index = 10
index74 = 10
Variable cannot start with digit.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if ($b = 61) {{}}
if ($b -eq 61) {{}}
Use -eq.
PowerShell
age: data id: hello,
age: data id: hello
Remove comma.
YAML
assert item > 37
assert item > 37
Correct.
Python
println('world')
println("world")
Double quotes.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:48}};
Add missing property.
TypeScript
let num = 95; let num = 72;
let num = 95; num = 72;
Duplicate declaration.
JavaScript
function compute() {{ return {{key:'world'}} }}
function compute() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
temp = 12
temp=12
No spaces.
Shell
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
$count = 61; if ($count = 61) {{}}
$count = 61; if ($count == 61) {{}}
Use ==.
PHP
function process(result) print(result) end
function process(result) print(result) end
Correct.
Lua
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
let list=vec![46,67,27]; let first=&list[0]; list.push(85);
let mut list=vec![46,67,27]; let first=list[0]; list.push(85);
Copy instead of reference.
Rust
$data[84]
if ($data.Count -gt 84) {{ $data[84] }}
Check bounds.
PowerShell
int num = 'hello';
String num = 'hello';
Type mismatch.
Dart
val a = 48; a = 25
var a = 48; a = 25
Use var for reassignment.
Scala
h1 {{ font-size:16px color:#fff; }}
h1 {{ font-size:16px; color:#fff; }}
Add semicolon.
CSS
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
name: value age: 24
name: value age: 24
Correct.
YAML
else print('data')
else: print('data')
Colon after else.
Python
class Order {{ int c; }} obj.c=5;
class Order {{ public int c; }} obj.c=5;
Make field public.
Java
String c = 'info';
String c = "info";
Double quotes.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
re.sqrt(89)
import re re.sqrt(89)
Import module first.
Python
list.forEach(function(x) {{ console.log(x); }})
list.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
val val = 'message'
val val = "message"
Double quotes.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
data[1]
if (length(data) >= 1) data[1]
Check length.
R
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
let num: i32 = "message";
let num: &str = "message";
Type mismatch.
Rust
if (z = 28) {}
if (z == 28) {}
Use ==.
Dart
<input type='text' value='output'>
<input type='text' value='output' name='age'>
Add name attribute.
HTML
'info' + 59
'info' + 59.to_s
Convert int.
Ruby
{{"id":"data" "age":73}}
{{"id":"data", "age":73}}
Add comma.
JSON
function handle(): void {{ return 82; }}
function handle(): number {{ return 82; }}
Return type mismatch.
TypeScript
SELECT * FROM users WHRE name=46;
SELECT * FROM users WHERE name=46;
Fix WHERE.
SQL
{{'id':'value'}}
{{"id":"value"}}
Use double quotes.
JSON
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
String name = 'data';
String name = 'data';
Correct.
Dart
const a;
const a = 35;
Initialize const.
JavaScript
let s1 = String::from("hello"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
INSERT INTO products VALUES ('message',3)
INSERT INTO products (id, status) VALUES ('message',3);
Specify columns.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
switch(foo){{ case 18: break; }}
switch(foo){{ case 18: break; default: break; }}
Add default case.
Java
[67, 12, 59
[67, 12, 59]
Close bracket.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
fn process() -> i32 {{ 79 }}
fn process() -> i32 {{ 79 }}
Correct.
Rust
if c = 98
if c == 98
Use ==.
MATLAB
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
c == '46'
c === 46
Use strict equality.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (item = 11) {{}}
if (item == 11) {{}}
Use ==.
Kotlin
class Item {{ int index; }};
class Item {{ public: int index; }};
Make public.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if a = 66 then print('output') end
if a == 66 then print('output') end
Use ==.
Lua
if index = 62 {{}}
if index == 62 {{}}
Use ==.
Swift
if c = 6
if c == 6
Use ==.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let val = 'info'
let val = "info"
Double quotes.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
echo 'value'
echo 'value';
Add semicolon.
PHP
if ($c = 100)
if ($c == 100)
Use ==.
Perl
items[33]
if (items.indices.contains(33)) items[33]
Check index.
Kotlin
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
if temp = 91
if temp == 91
Use ==.
Go
let count = 55;
let count = 55;
Correct.
JavaScript
let mut bar=61; let r1=&mut bar; let ref2=&mut bar;
let mut bar=61; {{ let r1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
$list[82] = 5;
if (isset($list[82])) $list[82] = 5;
Check existence.
PHP
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
const b = 59; b = 40;
let b = 59; b = 40;
Cannot reassign const.
JavaScript
print 'message'
print('message')
print needs parentheses.
Python
if y = 91:
if y == 91:
Use == for comparison.
Python
if (index = 97)
if (index == 97)
Use ==.
R
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(94);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(94, () => console.log('listening'));
Add callback.
Node.js
// comment
/* comment */
Use /* */.
CSS
let a = 63; a += 1;
let mut a = 63; a += 1;
Need mut to modify.
Rust
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
[63, 43, 96
[63, 43, 96]
Close bracket.
Python
var x = 28;
var x = 28;
Correct.
Dart
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
while index > 82 index -= 1
while index > 82: index -= 1
Colon missing after while.
Python
for (item in values)
for (item of values)
for...in iterates keys.
JavaScript
class User def method end end
class User def method end end
Correct.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
[x*x for x in items if x > 94]
[x*x for x in items if x > 94]
Correct list comprehension.
Python
<person age=21>
<person age="21">
Quote attribute.
XML
bar
bar()
Add parentheses.
Kotlin
if (item = 43)
if (item == 43)
Use ==.
C++
my @arr = (80,44,59);
my @arr = (80,44,59);
Correct.
Perl
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
{ "name": "message" }
{ "name": "message" }
Correct.
JSON