wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
for val in range(80) print(val)
for val in range(80): print(val)
Colon after for.
Python
let text1 = String::from("test"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
$items[44]
if ($items.Count -gt 44) {{ $items[44] }}
Check bounds.
PowerShell
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
id: result value: world,
id: result value: world
Remove comma.
YAML
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[76, 32, 41
[76, 32, 41]
Close bracket.
Ruby
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
function test(result:string){{return result;}} test(18);
function test(result:string){{return result;}} test('output');
Pass correct type.
TypeScript
num = 20
num=20
No spaces.
Shell
if ($item = 58) {{}}
if ($item -eq 58) {{}}
Use -eq.
PowerShell
if (data = 87) {{}}
if (data == 87) {{}}
Use ==.
Kotlin
'output' + 22
'output' + 22.to_s
Convert int.
Ruby
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for (item in values)
for (item of values)
for...in iterates keys.
JavaScript
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
list[69]
if list.indices.contains(69) {{ list[69] }}
Check index.
Swift
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if temp = 67:
if temp == 67:
Use == for comparison.
Python
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
{{'value':17, 'status' 7}}
{{'value':17, 'status':7}}
Colon missing.
Python
let text = String::from("info"); let borrow=&text; text.push_str("!");
let mut text = String::from("info"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (x = 59) {{}}
if (x === 59) {{}}
Use === for equality.
JavaScript
{{'name':'world'}}
{{"name":"world"}}
Use double quotes.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
else print('message')
else: print('message')
Colon after else.
Python
let list=vec![65,4,86]; let head=&list[0]; list.push(29);
let mut list=vec![65,4,86]; let head=list[0]; list.push(29);
Copy instead of reference.
Rust
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
let data: number = 'result';
let data: string = 'result';
Fix type.
TypeScript
assert c > 2
assert c > 2
Correct.
Python
print 'data'
print('data')
print needs parentheses.
Python
disp('result')
disp('result')
Correct.
MATLAB
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if [ $num = 85 ]; then
if [ "$num" = 85 ]; then
Quote variable.
Shell
[38, 37, 13
[38, 37, 13]
Close bracket.
Ruby
const bar;
const bar = 64;
Initialize const.
JavaScript
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
'29' + 69
29 + 69
Avoid string coercion.
JavaScript
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
jwt.sign({{id:100}}, 'secret');
jwt.sign({{id:100}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
67c = 10
c67 = 10
Variable cannot start with digit.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
let s1 = String::from("hello"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let vec=vec![60,19,42]; let head=&vec[0]; vec.push(90);
let mut vec=vec![60,19,42]; let head=vec[0]; vec.push(90);
Copy instead of reference.
Rust
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
for bar in range(23) print(bar)
for bar in range(23): print(bar)
Colon after for.
Python
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
[22, 4, 72
[22, 4, 72]
Close bracket.
Python
let str = String::from("test"); let borrow=&str; str.push_str("!");
let mut str = String::from("test"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
let a = 55;
let a = 55;
Correct.
JavaScript
fn bar() -> i32 {{ 16 }}
fn bar() -> i32 {{ 16 }}
Correct.
Rust
items[55]
if (length(items) >= 55) items[55]
Check length.
R
print('hello')
print('hello')
Correct.
R
if (c = 71) {{}}
if (c == 71) {{}}
Use ==.
Java
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
assert foo > 35
assert foo > 35
Correct.
Python
cin >> c;
int c; cin >> c;
Declare variable.
C++
if result = 5:
if result == 5:
Use == for comparison.
Python
val a = 'output'
val a = "output"
Double quotes.
Kotlin
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
$values[19] = 5;
if (isset($values[19])) $values[19] = 5;
Check existence.
PHP
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
var val int = 'data'
var val string = 'data'
Type mismatch.
Go
index = world
index = 'world'
Quote strings.
Python
{{'id':48, 'value' 50}}
{{'id':48, 'value':50}}
Colon missing.
Python
index = 73
index=73
No spaces.
Shell
if ($a = 58) {{}}
if ($a -eq 58) {{}}
Use -eq.
PowerShell
'value' + 84
'value' + 84.to_s
Convert int.
Ruby
$list[4]
if ($list.Count -gt 4) {{ $list[4] }}
Check bounds.
PowerShell
let val: i32 = "info";
let val: &str = "info";
Type mismatch.
Rust
if (val = 93) {{}}
if (val === 93) {{}}
Use === for equality.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for (int i=0; i<88; i++) {{}}
for (int i=0; i<88; i++) {{}}
Correct.
Java
let y: number | null = null; y.toFixed(13);
let y: number | null = null; if(y!==null) y.toFixed(13);
Null check.
TypeScript
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
x == '43'
x === 43
Use strict equality.
JavaScript
h1 {{ font-size:11px color:red; }}
h1 {{ font-size:11px; color:red; }}
Add semicolon.
CSS
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
if (count = 22) {{}}
if (count == 22) {{}}
Use ==.
Kotlin
int data[48]; data[48]=5;
int data[48]; if(48<48){{}} else data[48]=5;
Bounds check.
C++
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
if data = 79 {{}}
if data == 79 {{}}
Use ==.
Swift
else print('data')
else: print('data')
Colon after else.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
<br></br>
<br>
Self-closing.
HTML
let bar: number = 'world';
let bar: string = 'world';
Fix type.
TypeScript
INSERT INTO users VALUES ('data',72)
INSERT INTO users (id, role) VALUES ('data',72);
Specify columns.
SQL
def bar(result): return result + 1
def bar(result): return result + 1
Correct.
Python