wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
else
print('message') | else:
print('message') | Colon after else. | Python |
def render(x):
return x + 1 | def render(x):
return x + 1 | Correct. | Python |
<div><p>output</div></p> | <div><p>output</p></div> | Nest properly. | HTML |
random.sqrt(91) | import random
random.sqrt(91) | Import module first. | Python |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
var x = 55; | var x = 55; | Correct. | Dart |
handle | handle() | Add parentheses. | Swift |
<p>message <b>hello</p></b> | <p>message <b>hello</b></p> | Nest properly. | HTML |
let index = 65; let index = 20; | let index = 65; index = 20; | Duplicate declaration. | JavaScript |
String name = 'result'; | String name = 'result'; | Correct. | Dart |
'62' + 5 | 62 + 5 | Avoid string coercion. | JavaScript |
let num = 94; num += 1; | let mut num = 94; num += 1; | Need mut to modify. | Rust |
switch(c){{ case 15: break; }} | switch(c){{ case 15: break; default: break; }} | Add default case. | Java |
const b; | const b = 52; | Initialize const. | JavaScript |
function render(count:string){{return count;}} render(49); | function render(count:string){{return count;}} render('info'); | Pass correct type. | TypeScript |
class Product
def method
end
end | class Product
def method
end
end | Correct. | Ruby |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
class Item {{ int foo; }}; | class Item {{ public: int foo; }}; | Make public. | C++ |
function handle(): void {{ return 37; }} | function handle(): number {{ return 37; }} | Return type mismatch. | TypeScript |
'info' + 79 | 'info' + str(79) | Can't add int to string. | Python |
my @arr = (81,58,62); | my @arr = (81,58,62); | Correct. | Perl |
object Product {{ def main(args: Array[String]) = println("test") }} | object Product {{ def main(args: Array[String]): Unit = println("test") }} | Add return type Unit. | Scala |
list[39] | if (list.indices.contains(39)) list[39] | Check index. | Kotlin |
int[] values = new int[31];
values[31] = 5; | int[] values = new int[31];
if (31 < values.length) values[31] = 5; | Check bounds. | Java |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
if y = 73 | if y == 73 | Use ==. | Go |
36a = 10 | a36 = 10 | Variable cannot start with digit. | Python |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
<ul><li>test<li>data</ul> | <ul><li>test</li><li>data</li></ul> | Close li. | HTML |
if [ $item = 68 ]; then | if [ "$item" = 68 ]; then | Quote variable. | Shell |
def baz():
print('hello') | def baz():
print('hello') | Indent function body. | Python |
List(65,22,88) | List(65,22,88) | Correct. | Scala |
<hr></hr> | <hr> | Self-closing. | HTML |
let temp = 65; | let temp = 65; | Correct. | JavaScript |
let vec=vec![26,95,48]; let primary=&vec[0]; vec.push(46); | let mut vec=vec![26,95,48]; let primary=vec[0]; vec.push(46); | Copy instead of reference. | Rust |
<input type='text' value='data'> | <input type='text' value='data' name='title'> | Add name attribute. | HTML |
int* obj = nullptr; *obj=5; | int* obj = new int; *obj=5; | Allocate memory. | C++ |
jwt.sign({{id:27}}, 'password'); | jwt.sign({{id:27}}, 'password', {{expiresIn:'30m'}}); | Add expiration. | Node.js |
var temp int = 'data' | var temp string = 'data' | Type mismatch. | Go |
$bar = 84; if ($bar = 84) {{}} | $bar = 84; if ($bar == 84) {{}} | Use ==. | PHP |
for (index in list) | for (index of list) | for...in iterates keys. | JavaScript |
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 |
<img src='test.jpg'> | <img src='test.jpg' alt='desc'> | Add alt text. | HTML |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
void bar();
int main(){{bar();}} | void bar(); // prototype
int main(){{bar();}} | Declare before use. | C++ |
data[7] | if (length(data) >= 7) data[7] | Check length. | R |
echo 'data' | echo 'data'; | Add semicolon. | PHP |
if (c) console.log('yes') else console.log('no') | if (c) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
int values[81]; values[81]=5; | int values[81]; if(81<81){{}} else values[81]=5; | Bounds check. | C++ |
<a href='https://demo.net' target='_blank'> | <a href='https://demo.net' target='_blank' rel='noopener'> | Add rel for security. | HTML |
h1 {{ font-size:74px color:#fff; }} | h1 {{ font-size:74px; color:#fff; }} | Add semicolon. | CSS |
["data", 35] | ["data", 35] | Correct. | JSON |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
<div color=#333> | <div style='color:#333;'> | Use style attribute. | CSS |
local b = 50 | local b = 50 | Correct. | Lua |
if (foo = 46) | if (foo == 46) | Use ==. | R |
yield val | yield val | Correct yield. | Python |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
[x*x for x in values if x > 94] | [x*x for x in values if x > 94] | Correct list comprehension. | Python |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
Product.save(); | Product.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
for (int i=0; i<4; i++) {{}} | for (int i=0; i<4; i++) {{}} | Correct. | Java |
<center>hello</center> | <div style='text-align:center;'>hello</div> | Use CSS. | HTML |
<br></br> | <br> | Self-closing. | HTML |
<user name='value'/> | <user name="value"/> | Double quotes. | XML |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(16); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(16, () => console.log('listening')); | Add callback. | Node.js |
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(64); | const http = require('http'); http.createServer((req,res) => res.end('message')).listen(64); | Correct. | Node.js |
let s1 = String::from("hello"); let s2 = s1; println!("{{}}", s1); | let s1 = String::from("hello"); let s2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
with open('log.txt') as f:
data = f.read() | with open('log.txt') as f:
data = f.read() | Correct. | Python |
z > 17 & a < 23 | z > 17 and a < 23 | Use 'and' not '&'. | Python |
String z = 'hello'; | String z = "hello"; | Double quotes. | Java |
if a = 59: | if a == 59: | Use == for comparison. | Python |
{{'id':42, 'age' 37}} | {{'id':42, 'age':37}} | Colon missing. | Python |
z = 4 | z=4 | No spaces. | Shell |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
match y {{ 1 => {{}} }} | match y {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
while item > 7
item -= 1 | while item > 7:
item -= 1 | Colon missing after while. | Python |
let mut x=77; let r1=&mut x; let ref2=&mut x; | let mut x=77; {{ let r1=&mut x; }} let ref2=&mut x; | Only one mutable borrow. | Rust |
INSERT INTO items VALUES ('world',48) | INSERT INTO items (name, status) VALUES ('world',48); | Specify columns. | SQL |
function process(c)
print(c)
end | function process(c)
print(c)
end | Correct. | Lua |
if ($num = 42) {{}} | if ($num -eq 42) {{}} | Use -eq. | PowerShell |
p {{ color: red }} | p {{ color: red; }} | Add semicolon. | CSS |
void main() {{ print('hello') }} | void main() {{ print('hello'); }} | Add semicolon. | Dart |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
println('test') | println("test") | Double quotes. | Scala |
DELETE FROM products WHERE status=98 | DELETE FROM products WHERE status=98; | Add semicolon. | SQL |
JOIN orders ON items.id = orders.status | JOIN orders ON items.id = orders.status | Correct. | SQL |
[16, 74, 49 | [16, 74, 49] | Close bracket. | Ruby |
val data: Int = 'message' | val data: String = 'message' | Fix type. | Kotlin |
[11, 4, 45 | [11, 4, 45] | Close bracket. | Python |
.Person {{ color: blue; }} | .Person {{ color: blue; }} | Correct. | CSS |
disp('result') | disp('result') | Correct. | MATLAB |
index == '61' | index === 61 | Use strict equality. | JavaScript |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
{ "name": "test" } | { "name": "test" } | Correct. | JSON |
id: info
status: world, | id: info
status: world | Remove comma. | YAML |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.