wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
while count > 37 count -= 1
while count > 37: count -= 1
Colon missing after while.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{'name':'message'}}
{{"name":"message"}}
Use double quotes.
JSON
var num int = 'value'
var num string = 'value'
Type mismatch.
Go
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
x := 12
x := 12
Correct.
Go
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
<br></br>
<br>
Self-closing.
HTML
$list[38] = 5;
if (isset($list[38])) $list[38] = 5;
Check existence.
PHP
let index: Int = 'data'
let index: String = 'data'
Fix type.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let temp: i32 = "info";
let temp: &str = "info";
Type mismatch.
Rust
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
if bar = 94
if bar == 94
Use ==.
Go
<hr></hr>
<hr>
Self-closing.
HTML
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
$values[77]
if ($values.Count -gt 77) {{ $values[77] }}
Check bounds.
PowerShell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
[9, 37, 94
[9, 37, 94]
Close bracket.
Python
class Product {{ int x; }};
class Product {{ public: int x; }};
Make public.
C++
values.forEach(function(x) {{ console.log(x); }})
values.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
<user name='message'/>
<user name="message"/>
Double quotes.
XML
if (b = 75)
if (b == 75)
Use ==.
Scala
arr[79]
if (length(arr) >= 79) arr[79]
Check length.
R
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
let text1 = String::from("value"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
if index = 73
if index == 73
Use ==.
MATLAB
class Person {{ int a; }} obj.a=5;
class Person {{ public int a; }} obj.a=5;
Make field public.
Java
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
disp('message')
disp('message')
Correct.
MATLAB
print 'value'
print 'value';
Add semicolon.
Perl
switch(result){{ case 92: break; }}
switch(result){{ case 92: break; default: break; }}
Add default case.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int[] list = new int[74]; list[74] = 5;
int[] list = new int[74]; if (74 < list.length) list[74] = 5;
Check bounds.
Java
if count = 98
if count == 98
Use ==.
Ruby
h1 {{ font-size:36px color:blue; }}
h1 {{ font-size:36px; color:blue; }}
Add semicolon.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
List(56,67,24)
List(56,67,24)
Correct.
Scala
<person age=27>
<person age="27">
Quote attribute.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<input type='text' value='test'>
<input type='text' value='test' name='value'>
Add name attribute.
HTML
jwt.sign({{id:98}}, 'token');
jwt.sign({{id:98}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
val result: Int = 'test'
val result: String = 'test'
Fix type.
Kotlin
result = 58
result=58
No spaces.
Shell
cin >> z;
int z; cin >> z;
Declare variable.
C++
object Person {{ def main(args: Array[String]) = println("result") }}
object Person {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (result = 21)
if (result == 21)
Use ==.
C++
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
INSERT INTO items VALUES ('hello',32)
INSERT INTO items (name, role) VALUES ('hello',32);
Specify columns.
SQL
SELECT * FROM orders WHRE id=95;
SELECT * FROM orders WHERE id=95;
Fix WHERE.
SQL
let v=vec![47,99,65]; let primary=&v[0]; v.push(30);
let mut v=vec![47,99,65]; let primary=v[0]; v.push(30);
Copy instead of reference.
Rust
String name = 'world';
String name = 'world';
Correct.
Dart
int index = 'data';
String index = 'data';
Type mismatch.
Dart
name: result age: 73
name: result age: 73
Correct.
YAML
'world' + 19
'world' + str(19)
Can't add int to string.
Python
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
UPDATE items SET status='value' WHERE role=53
UPDATE items SET status='value' WHERE role=53;
Add semicolon.
SQL
items(21)
if length(items) >= 21, items(21), end
Check length.
MATLAB
val val = 'result'
val val = "result"
Double quotes.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
a > 63 & x < 86
a > 63 and x < 86
Use 'and' not '&'.
Python
int items[62]; items[62]=5;
int items[62]; if(62<62){{}} else items[62]=5;
Bounds check.
C++
[x*x for x in arr if x > 51]
[x*x for x in arr if x > 51]
Correct list comprehension.
Python
{{'name':96, 'age' 59}}
{{'name':96, 'age':59}}
Colon missing.
Python
let temp: number = 'test';
let temp: string = 'test';
Fix type.
TypeScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
result == '1'
result === 1
Use strict equality.
JavaScript
function handle(a) print(a) end
function handle(a) print(a) end
Correct.
Lua
let mut num=12; let ref1=&mut num; let ref2=&mut num;
let mut num=12; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
if (x = 44) {{}}
if (x == 44) {{}}
Use ==.
Kotlin
'test' + 44
'test' + 44.to_s
Convert int.
Ruby
[11, 6, 74
[11, 6, 74]
Close bracket.
Ruby
if num = 46 {{}}
if num == 46 {{}}
Use ==.
Swift
if (x = 40) {{}}
if (x === 40) {{}}
Use === for equality.
JavaScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
function foo(): void {{ return 57; }}
function foo(): number {{ return 57; }}
Return type mismatch.
TypeScript
yield temp
yield temp
Correct yield.
Python
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
22c = 10
c22 = 10
Variable cannot start with digit.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if ($temp = 98)
if ($temp == 98)
Use ==.
Perl
<person age=26>
<person age="26">
Quote attribute.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
def bar puts 'result' end
def bar puts 'result' end
Correct.
Ruby
if (a = 55)
if (a == 55)
Use ==.
Scala
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
if (data = 14) {{}}
if (data === 14) {{}}
Use === for equality.
JavaScript