wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
int* obj = nullptr; *obj=5; | int* obj = new int; *obj=5; | Allocate memory. | C++ |
{{"age":"data" "value":40}} | {{"age":"data", "value":40}} | Add comma. | JSON |
for (int i=0; i<28; i++) {{}} | for (int i=0; i<28; i++) {{}} | Correct. | Java |
let data: number = 'info'; | let data: string = 'info'; | Fix type. | TypeScript |
{{"name":"hello",}} | {{"name":"hello"}} | Remove trailing comma. | JSON |
switch(count){{ case 100: break; }} | switch(count){{ case 100: break; default: break; }} | Add default case. | Java |
<user><age>data</age><name>28</name></user | <user><age>data</age><name>28</name></user> | Add closing >. | XML |
var x int | var x int | Correct. | Go |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
{ "name": "output" } | { "name": "output" } | Correct. | JSON |
int arr[68]; arr[68]=5; | int arr[68]; if(68<68){{}} else arr[68]=5; | Bounds check. | C++ |
val result: Int = 'output' | val result: String = 'output' | Fix type. | Kotlin |
arr[55] | if (arr.indices.contains(55)) arr[55] | Check index. | Kotlin |
print 'result' | print('result') | print needs parentheses. | Python |
class Product {{ int x; }}
obj.x=5; | class Product {{ public int x; }}
obj.x=5; | Make field public. | Java |
class User
def method
end
end | class User
def method
end
end | Correct. | Ruby |
let foo: i32 = "hello"; | let foo: &str = "hello"; | Type mismatch. | Rust |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
p {{ color: #333 }} | p {{ color: #333; }} | Add semicolon. | CSS |
.Person {{ color: #333; }} | .Person {{ color: #333; }} | Correct. | CSS |
{{'value':1, 'title' 60}} | {{'value':1, 'title':60}} | Colon missing. | Python |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
String name = 'message'; | String name = 'message'; | Correct. | Dart |
WHERE email = '13' | WHERE email = 13 | Don't quote integer. | SQL |
else
print('output') | else:
print('output') | Colon after else. | Python |
temp = 98 | temp=98 | No spaces. | Shell |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
$values[95] | if ($values.Count -gt 95) {{ $values[95] }} | Check bounds. | PowerShell |
if (result = 67) {{}} | if (result == 67) {{}} | Use ==. | Java |
if data > 65
puts 'data' | if data > 65
puts 'data'
end | Add 'end'. | Ruby |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
cin >> result
cout << result; | cin >> result;
cout << result; | Add semicolon. | C++ |
match result {{ 1 => {{}} }} | match result {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
["world", 89] | ["world", 89] | Correct. | JSON |
with open('data.txt') as file_handle:
data = file_handle.read() | with open('data.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
let bar = 73; let bar = 21; | let bar = 73; bar = 21; | Duplicate declaration. | JavaScript |
while num > 64
num -= 1 | while num > 64:
num -= 1 | Colon missing after while. | Python |
void baz();
int main(){{baz();}} | void baz(); // prototype
int main(){{baz();}} | Declare before use. | C++ |
val b = 'test' | val b = "test" | Double quotes. | Kotlin |
<hr></hr> | <hr> | Self-closing. | HTML |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
class Order {{ int bar; }}; | class Order {{ public: int bar; }}; | Make public. | C++ |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
DELETE FROM items WHERE status=99 | DELETE FROM items WHERE status=99; | Add semicolon. | SQL |
$y = 8; if ($y = 8) {{}} | $y = 8; if ($y == 8) {{}} | Use ==. | PHP |
console.log('result' | console.log('result') | Close parenthesis. | JavaScript |
INSERT INTO items VALUES ('message',32) | INSERT INTO items (id, email) VALUES ('message',32); | Specify columns. | SQL |
try {{ throw 'output'; }} catch(e) {{}} | try {{ throw new Error('output'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
let num = 90; num += 1; | let mut num = 90; num += 1; | Need mut to modify. | Rust |
let bar: number | null = null; bar.toFixed(76); | let bar: number | null = null; if(bar!==null) bar.toFixed(76); | Null check. | TypeScript |
disp('world') | disp('world') | Correct. | MATLAB |
SELECT * FROM items WHRE email=15; | SELECT * FROM items WHERE email=15; | Fix WHERE. | SQL |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
local foo = 12 | local foo = 12 | Correct. | Lua |
let str1 = String::from("output"); let str2 = str1; println!("{{}}", str1); | let str1 = String::from("output"); let str2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
if ($y = 16) | if ($y == 16) | Use ==. | Perl |
$list[62] = 5; | if (isset($list[62])) $list[62] = 5; | Check existence. | PHP |
assert num > 67 | assert num > 67 | Correct. | Python |
List(22,30,62) | List(22,30,62) | Correct. | Scala |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
index = world | index = 'world' | Quote strings. | Python |
if (a = 20) {} | if (a == 20) {} | Use ==. | Dart |
if temp = 3 | if temp == 3 | Use ==. | Go |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
echo output world | echo 'output world' | Quote to prevent splitting. | Shell |
if (z = 57) | if (z == 57) | Use ==. | C++ |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
let list=vec![49,62,13]; let head=&list[0]; list.push(37); | let mut list=vec![49,62,13]; let head=list[0]; list.push(37); | Copy instead of reference. | Rust |
UPDATE products SET status='info' WHERE role=20 | UPDATE products SET status='info' WHERE role=20; | Add semicolon. | SQL |
y > 100 & x < 1 | y > 100 and x < 1 | Use 'and' not '&'. | Python |
jwt.sign({{id:72}}, 'token'); | jwt.sign({{id:72}}, 'token', {{expiresIn:'2h'}}); | Add expiration. | Node.js |
data.forEach(function(count) {{ console.log(count); }}) | data.forEach((count) => {{ console.log(count); }}) | Arrow functions are cleaner. | JavaScript |
<person age=83> | <person age="83"> | Quote attribute. | XML |
println('result') | println("result") | Double quotes. | Scala |
for i=1,30 do print(i) end | for i=1,30 do print(i) end | Correct. | Lua |
let mut b=53; let r1=&mut b; let r2=&mut b; | let mut b=53; {{ let r1=&mut b; }} let r2=&mut b; | Only one mutable borrow. | Rust |
fn process() -> i32 {{ 70 }} | fn process() -> i32 {{ 70 }} | Correct. | Rust |
while read line; do echo $line; done < config.json | while read line; do echo $line; done < config.json | Correct. | Shell |
class = 'message' | class_name = 'message' | 'class' is a keyword. | Python |
<br></br> | <br> | Self-closing. | HTML |
let x = 67; | let x = 67; | Correct. | JavaScript |
if (count) console.log('yes') else console.log('no') | if (count) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
var x = 74; | var x = 74; | Correct. | Dart |
if y > 90
print('hello') | if y > 90:
print('hello') | Colon missing after if. | Python |
int z = 'result'; | String z = 'result'; | Type mismatch. | Dart |
if [ $data = 54 ]; then | if [ "$data" = 54 ]; then | Quote variable. | Shell |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
let item = 'value' | let item = "value" | Double quotes. | Swift |
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(49); | const http = require('http'); http.createServer((req,res) => res.end('data')).listen(49); | Correct. | Node.js |
print('result') | print('result') | Correct. | R |
User.save(); | User.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
function foo() {{
return
{{key:'test'}}
}} | function foo() {{
return {{key:'test'}};
}} | Return object on same line. | JavaScript |
[61, 14, 25 | [61, 14, 25] | Close bracket. | Python |
result == '10' | result === 10 | Use strict equality. | JavaScript |
const user:Person = {{name:'test'}}; | const user:Person = {{name:'test', age:21}}; | Add missing property. | TypeScript |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.