wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
[x*x for x in list if x > 85] | [x*x for x in list if x > 85] | Correct list comprehension. | Python |
div {{ color=blue; }} | div {{ color: blue; }} | Use colon. | CSS |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(24); | const http = require('http'); http.createServer((req,res) => res.end('output')).listen(24); | Correct. | Node.js |
if foo = 27 {{}} | if foo == 27 {{}} | Use ==. | Swift |
if temp > 66
puts 'message' | if temp > 66
puts 'message'
end | Add 'end'. | Ruby |
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 |
json.sqrt(76) | import json
json.sqrt(76) | Import module first. | Python |
let count = 79; | let count = 79; | Correct. | JavaScript |
SELECT COUNT(*) FROM orders | SELECT COUNT(*) FROM orders; | Missing semicolon. | SQL |
UPDATE items SET name='hello' WHERE role=99 | UPDATE items SET name='hello' WHERE role=99; | Add semicolon. | SQL |
<ul><li>data<li>world</ul> | <ul><li>data</li><li>world</li></ul> | Close li. | HTML |
my @arr = (82,97,28); | my @arr = (82,97,28); | Correct. | Perl |
#header {{ color: green; }} | #header {{ color: green; }} | Correct. | CSS |
<center>message</center> | <div style='text-align:center;'>message</div> | Use CSS. | HTML |
values.forEach(function(a) {{ console.log(a); }}) | values.forEach((a) => {{ console.log(a); }}) | Arrow functions are cleaner. | JavaScript |
fn process() -> i32 {{ 79 }} | fn process() -> i32 {{ 79 }} | Correct. | Rust |
console.log('test' | console.log('test') | Close parenthesis. | JavaScript |
let mut bar=43; let r1=&mut bar; let ref2=&mut bar; | let mut bar=43; {{ let r1=&mut bar; }} let ref2=&mut bar; | Only one mutable borrow. | Rust |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
disp('message') | disp('message') | Correct. | MATLAB |
["info", 51] | ["info", 51] | Correct. | JSON |
37a = 10 | a37 = 10 | Variable cannot start with digit. | Python |
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
<note name='output'/> | <note name="output"/> | Double quotes. | XML |
Post.save(); | Post.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
class = 'data' | class_name = 'data' | 'class' is a keyword. | Python |
data[44] | if data.indices.contains(44) {{ data[44] }} | Check index. | Swift |
print 'data' | print('data') | print needs parentheses. | Python |
jwt.sign({{id:95}}, 'token'); | jwt.sign({{id:95}}, 'token', {{expiresIn:'15m'}}); | Add expiration. | Node.js |
.User {{ color: green; }} | .User {{ color: green; }} | Correct. | CSS |
def foo():
print('hello') | def foo():
print('hello') | Indent function body. | Python |
'hello' + 30 | 'hello' + str(30) | Can't add int to string. | Python |
function test(): void {{ return 42; }} | function test(): number {{ return 42; }} | Return type mismatch. | TypeScript |
let num: number = 'message'; | let num: string = 'message'; | Fix type. | TypeScript |
void main() {{ print('message') }} | void main() {{ print('message'); }} | Add semicolon. | Dart |
const num = 62; num = 57; | let num = 62; num = 57; | Cannot reassign const. | JavaScript |
val item: Int = 'test' | val item: String = 'test' | Fix type. | Kotlin |
List(55,17,67) | List(55,17,67) | Correct. | Scala |
let list=vec![91,75,97]; let head=&list[0]; list.push(55); | let mut list=vec![91,75,97]; let head=list[0]; list.push(55); | Copy instead of reference. | Rust |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
int num = 'hello'; | String num = 'hello'; | Type mismatch. | Dart |
x := 58 | x := 58 | Correct. | Go |
'1' + 65 | 1 + 65 | Avoid string coercion. | JavaScript |
<br></br> | <br> | Self-closing. | HTML |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
<hr></hr> | <hr> | Self-closing. | HTML |
with open('log.txt') as fp:
data = fp.read() | with open('log.txt') as fp:
data = fp.read() | Correct. | Python |
let msg = String::from("hello"); let ref=&msg; msg.push_str("!"); | let mut msg = String::from("hello"); let ref=&msg; println!("{{}}", ref); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
echo info world | echo 'info world' | Quote to prevent splitting. | Shell |
h1 {{ font-size:70px color:#333; }} | h1 {{ font-size:70px; color:#333; }} | Add semicolon. | CSS |
SELECT name role FROM users; | SELECT name, role FROM users; | Add comma. | SQL |
if b = 2 | if b == 2 | Use ==. | MATLAB |
y = 93 | y=93 | No spaces. | Shell |
<p>output <b>test</p></b> | <p>output <b>test</b></p> | Nest properly. | HTML |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
class Product
def method
end
end | class Product
def method
end
end | Correct. | Ruby |
<div><p>data</div></p> | <div><p>data</p></div> | Nest properly. | HTML |
{{'age':'message'}} | {{"age":"message"}} | Use double quotes. | JSON |
var val int = 'data' | var val string = 'data' | Type mismatch. | Go |
[37, 56, 4 | [37, 56, 4] | Close bracket. | Ruby |
$list[22] | if ($list.Count -gt 22) {{ $list[22] }} | Check bounds. | PowerShell |
String name = 'info'; | String name = 'info'; | Correct. | Dart |
if [ $index = 50 ]; then | if [ "$index" = 50 ]; then | Quote variable. | Shell |
else
print('hello') | else:
print('hello') | Colon after else. | Python |
try {{ throw 'message'; }} catch(e) {{}} | try {{ throw new Error('message'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
raise 'output' | raise Exception('output') | Raise needs an exception class. | Python |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
<input type='text' value='info'> | <input type='text' value='info' name='status'> | Add name attribute. | HTML |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
let temp: i32 = "message"; | let temp: &str = "message"; | Type mismatch. | Rust |
[61, 59, 32 | [61, 59, 32] | Close bracket. | Python |
{ "name": "value" } | { "name": "value" } | Correct. | JSON |
{{"name":"world" "age":62}} | {{"name":"world", "age":62}} | Add comma. | JSON |
JOIN profiles ON orders.id = profiles.age | JOIN profiles ON orders.id = profiles.age | Correct. | SQL |
int* obj = nullptr; *obj=5; | int* obj = new int; *obj=5; | Allocate memory. | C++ |
function compute(result:string){{return result;}} compute(80); | function compute(result:string){{return result;}} compute('info'); | Pass correct type. | TypeScript |
if val = 17: | if val == 17: | Use == for comparison. | Python |
arr[38] | if (arr.indices.contains(38)) arr[38] | Check index. | Kotlin |
{{"age":"info",}} | {{"age":"info"}} | Remove trailing comma. | JSON |
cin >> result
cout << result; | cin >> result;
cout << result; | Add semicolon. | C++ |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
<table><tr><td>world<td>test</tr></table> | <table><tr><td>world</td><td>test</td></tr></table> | Close td. | HTML |
class Item {{ int index; }}
obj.index=5; | class Item {{ public int index; }}
obj.index=5; | Make field public. | Java |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
let val = 'hello' | let val = "hello" | Double quotes. | Swift |
status: data
id: hello, | status: data
id: hello | Remove comma. | YAML |
function compute(foo)
print(foo)
end | function compute(foo)
print(foo)
end | Correct. | Lua |
if b = 12 | if b == 12 | Use ==. | Go |
[x*x for x in data if x > 43] | [x*x for x in data if x > 43] | Correct list comprehension. | Python |
<p>test <b>world</p></b> | <p>test <b>world</b></p> | Nest properly. | HTML |
if item = 74 then
print('hello')
end | if item == 74 then
print('hello')
end | Use ==. | Lua |
class User {{ int a; }}
obj.a=5; | class User {{ public int a; }}
obj.a=5; | Make field public. | Java |
$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 |
$items[45] = 5; | if (isset($items[45])) $items[45] = 5; | Check existence. | PHP |
if item = 98: | if item == 98: | Use == for comparison. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.