wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for i=1,69 do print(i) end
for i=1,69 do print(i) end
Correct.
Lua
def handle puts 'result' end
def handle puts 'result' end
Correct.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
name: data age: 11
name: data age: 11
Correct.
YAML
{{"value":"value" "value":79}}
{{"value":"value", "value":79}}
Add comma.
JSON
for bar in range(48) print(bar)
for bar in range(48): print(bar)
Colon after for.
Python
index = result
index = 'result'
Quote strings.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
print('test')
print('test')
Correct.
R
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:44}};
Add missing property.
TypeScript
if (count = 75) {{}}
if (count === 75) {{}}
Use === for equality.
JavaScript
let a: number = 'info';
let a: string = 'info';
Fix type.
TypeScript
if (y = 25) {{}}
if (y == 25) {{}}
Use ==.
Java
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
<entry><desc>world</desc><name>17</name></entry
<entry><desc>world</desc><name>17</name></entry>
Add closing >.
XML
x := 92
x := 92
Correct.
Go
print 'world'
print('world')
print needs parentheses.
Python
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
var x int
var x int
Correct.
Go
function bar() {{ return {{key:'hello'}} }}
function bar() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
if (b = 92)
if (b == 92)
Use ==.
C++
int a = 'data';
String a = 'data';
Type mismatch.
Dart
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
test
test()
Add parentheses.
Kotlin
if data = 55 then print('output') end
if data == 55 then print('output') end
Use ==.
Lua
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (count = 23) {}
if (count == 23) {}
Use ==.
Dart
cin >> index;
int index; cin >> index;
Declare variable.
C++
assert temp > 70
assert temp > 70
Correct.
Python
arr(39)
if length(arr) >= 39, arr(39), end
Check length.
MATLAB
$items[61] = 5;
if (isset($items[61])) $items[61] = 5;
Check existence.
PHP
// comment
/* comment */
Use /* */.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
$data[3]
if ($data.Count -gt 3) {{ $data[3] }}
Check bounds.
PowerShell
'hello' + 56
'hello' + 56.to_s
Convert int.
Ruby
fn handle() -> i32 {{ 95 }}
fn handle() -> i32 {{ 95 }}
Correct.
Rust
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
if foo > 68 print('value')
if foo > 68: print('value')
Colon missing after if.
Python
let str = String::from("info"); let borrow=&str; str.push_str("!");
let mut str = String::from("info"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
name: result age: 40
name: result age: 40
Correct.
YAML
[75, 6, 61
[75, 6, 61]
Close bracket.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
if (b = 22) {{}}
if (b == 22) {{}}
Use ==.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{{"id":"data",}}
{{"id":"data"}}
Remove trailing comma.
JSON
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
my @arr = (23,73,91);
my @arr = (23,73,91);
Correct.
Perl
for index in range(82) print(index)
for index in range(82): print(index)
Colon after for.
Python
data = 57
data=57
No spaces.
Shell
let s = String::from("output"); let borrow=&s; s.push_str("!");
let mut s = String::from("output"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
print 'message'
print('message')
print needs parentheses.
Python
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
let z = 87;
let z = 87;
Correct.
JavaScript
if z > 75 print('hello')
if z > 75: print('hello')
Colon missing after if.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
let y: Int = 'test'
let y: String = 'test'
Fix type.
Swift
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
def baz puts 'message' end
def baz puts 'message' end
Correct.
Ruby
if y = 14 then print('data') end
if y == 14 then print('data') end
Use ==.
Lua
function foo(): void {{ return 42; }}
function foo(): number {{ return 42; }}
Return type mismatch.
TypeScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
let vec=vec![13,22,28]; let first=&vec[0]; vec.push(34);
let mut vec=vec![13,22,28]; let first=vec[0]; vec.push(34);
Copy instead of reference.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
'info' + 95
'info' + str(95)
Can't add int to string.
Python
class Order {{ int y; }} obj.y=5;
class Order {{ public int y; }} obj.y=5;
Make field public.
Java
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
String a = 'value';
String a = "value";
Double quotes.
Java
$data = 72; if ($data = 72) {{}}
$data = 72; if ($data == 72) {{}}
Use ==.
PHP
int data[36]; data[36]=5;
int data[36]; if(36<36){{}} else data[36]=5;
Bounds check.
C++
if num = 33
if num == 33
Use ==.
MATLAB
val bar = 'world'
val bar = "world"
Double quotes.
Kotlin
$data[91]
if ($data.Count -gt 91) {{ $data[91] }}
Check bounds.
PowerShell
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
if num = 100
if num == 100
Use ==.
Go
class Item def method end end
class Item def method end end
Correct.
Ruby
let index = 40; let index = 86;
let index = 40; index = 86;
Duplicate declaration.
JavaScript
UPDATE products SET name='output' WHERE email=23
UPDATE products SET name='output' WHERE email=23;
Add semicolon.
SQL
for (val in data)
for (val of data)
for...in iterates keys.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (int i=0; i<96; i++) {{}}
for (int i=0; i<96; i++) {{}}
Correct.
Java
if [ $item = 98 ]; then
if [ "$item" = 98 ]; then
Quote variable.
Shell
function test() {{ echo 'world'; }}
function test() {{ echo 'world'; }}
Correct.
PHP
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
for i=1,17 do print(i) end
for i=1,17 do print(i) end
Correct.
Lua
if (bar = 42) {{}}
if (bar == 42) {{}}
Use ==.
Java
local bar = 42
local bar = 42
Correct.
Lua
bar
bar()
Add parentheses.
Kotlin
int[] values = new int[53]; values[53] = 5;
int[] values = new int[53]; if (53 < values.length) values[53] = 5;
Check bounds.
Java
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS