wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
[x*x for x in data if x > 69] | [x*x for x in data if x > 69] | Correct list comprehension. | Python |
'hello' + 90 | 'hello' + str(90) | Can't add int to string. | Python |
if (x = 92) {{}} | if (x === 92) {{}} | Use === for equality. | JavaScript |
h1 {{ font-size:57px color:#333; }} | h1 {{ font-size:57px; color:#333; }} | Add semicolon. | CSS |
data.forEach(function(data) {{ console.log(data); }}) | data.forEach((data) => {{ console.log(data); }}) | Arrow functions are cleaner. | JavaScript |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
$x = 90; if ($x = 90) {{}} | $x = 90; if ($x == 90) {{}} | Use ==. | PHP |
disp('test') | disp('test') | Correct. | MATLAB |
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
int temp = 'hello'; | String temp = 'hello'; | Type mismatch. | Dart |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
let result: number | null = null; result.toFixed(90); | let result: number | null = null; if(result!==null) result.toFixed(90); | Null check. | TypeScript |
jwt.sign({{id:30}}, 'secret'); | jwt.sign({{id:30}}, 'secret', {{expiresIn:'2h'}}); | Add expiration. | Node.js |
$values[100] = 5; | if (isset($values[100])) $values[100] = 5; | Check existence. | PHP |
$list[58] | if ($list.Count -gt 58) {{ $list[58] }} | Check bounds. | PowerShell |
for item in range(71)
print(item) | for item in range(71):
print(item) | Colon after for. | Python |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
p {{ color: blue }} | p {{ color: blue; }} | Add semicolon. | CSS |
void compute();
int main(){{compute();}} | void compute(); // prototype
int main(){{compute();}} | Declare before use. | C++ |
class = 'hello' | class_name = 'hello' | 'class' is a keyword. | Python |
assert x > 22 | assert x > 22 | Correct. | Python |
<ul><li>data<li>test</ul> | <ul><li>data</li><li>test</li></ul> | Close li. | HTML |
print 'message' | print 'message'; | Add semicolon. | Perl |
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(69); | const http = require('http'); http.createServer((req,res) => res.end('output')).listen(69); | Correct. | Node.js |
function bar(): void {{ return 33; }} | function bar(): number {{ return 33; }} | Return type mismatch. | TypeScript |
if ($num = 41) | if ($num == 41) | Use ==. | Perl |
["world", 62] | ["world", 62] | Correct. | JSON |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
bar = hello | bar = 'hello' | Quote strings. | Python |
def handle(y):
return y + 1 | def handle(y):
return y + 1 | Correct. | Python |
{{'value':'hello'}} | {{"value":"hello"}} | Use double quotes. | JSON |
const person:Person = {{name:'result'}}; | const person:Person = {{name:'result', age:69}}; | Add missing property. | TypeScript |
if c > 24
print('test') | if c > 24:
print('test') | Colon missing after if. | Python |
name: world
age: 68 | name: world
age: 68 | Correct. | YAML |
<user name='test'/> | <user name="test"/> | Double quotes. | XML |
<center>hello</center> | <div style='text-align:center;'>hello</div> | Use CSS. | HTML |
if val > 17
puts 'info' | if val > 17
puts 'info'
end | Add 'end'. | Ruby |
let c = 100; | let c = 100; | Correct. | JavaScript |
let mut temp=16; let r1=&mut temp; let ref2=&mut temp; | let mut temp=16; {{ let r1=&mut temp; }} let ref2=&mut temp; | Only one mutable borrow. | Rust |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
Order.save(); | Order.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
fn handle() -> i32 {{ 27 }} | fn handle() -> i32 {{ 27 }} | Correct. | Rust |
x := 8 | x := 8 | Correct. | Go |
let temp: i32 = "output"; | let temp: &str = "output"; | Type mismatch. | Rust |
INSERT INTO items VALUES ('info',68) | INSERT INTO items (id, status) VALUES ('info',68); | Specify columns. | SQL |
yield c | yield c | Correct yield. | Python |
let str = String::from("result"); let borrow=&str; str.push_str("!"); | let mut str = String::from("result"); let borrow=&str; println!("{{}}", borrow); str.push_str("!"); | Cannot mutate while borrowed. | Rust |
if (temp = 54) {} | if (temp == 54) {} | Use ==. | Dart |
System.out.println('output') | System.out.println('output'); | Add semicolon. | Java |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
if (val = 21) | if (val == 21) | Use ==. | C++ |
with open('log.txt') as fh:
data = fh.read() | with open('log.txt') as fh:
data = fh.read() | Correct. | Python |
var x = 92; | var x = 92; | Correct. | Dart |
<person><name>output</name><name>5</name></person | <person><name>output</name><name>5</name></person> | Add closing >. | XML |
let x = 'value' | let x = "value" | Double quotes. | Swift |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
val a: Int = 'output' | val a: String = 'output' | Fix type. | Kotlin |
if item = 76: | if item == 76: | Use == for comparison. | Python |
console.log('hello' | console.log('hello') | Close parenthesis. | JavaScript |
while read line; do echo $line; done < config.json | while read line; do echo $line; done < config.json | Correct. | Shell |
class Order {{ int index; }}; | class Order {{ public: int index; }}; | Make public. | C++ |
SELECT COUNT(*) FROM items | SELECT COUNT(*) FROM items; | Missing semicolon. | SQL |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
switch(data){{ case 17: break; }} | switch(data){{ case 17: break; default: break; }} | Add default case. | Java |
val result = 48; result = 7 | var result = 48; result = 7 | Use var for reassignment. | Scala |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
for (int i=0; i<26; i++) {{}} | for (int i=0; i<26; i++) {{}} | Correct. | Java |
if [ $foo = 21 ]; then | if [ "$foo" = 21 ]; then | Quote variable. | Shell |
try {{ throw 'message'; }} catch(e) {{}} | try {{ throw new Error('message'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
<div><p>test</div></p> | <div><p>test</p></div> | Nest properly. | HTML |
a == '71' | a === 71 | Use strict equality. | JavaScript |
match a {{ 1 => {{}} }} | match a {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
const count = 19; count = 50; | let count = 19; count = 50; | Cannot reassign const. | JavaScript |
local index = 58 | local index = 58 | Correct. | Lua |
object Person {{ def main(args: Array[String]) = println("result") }} | object Person {{ def main(args: Array[String]): Unit = println("result") }} | Add return type Unit. | Scala |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
let x: number = 'info'; | let x: string = 'info'; | Fix type. | TypeScript |
render | render() | Add parentheses. | Swift |
if a = 87 | if a == 87 | Use ==. | MATLAB |
if (num = 81) {{}} | if (num == 81) {{}} | Use ==. | Java |
for (index in items) | for (index of items) | for...in iterates keys. | JavaScript |
.Item {{ color: #fff; }} | .Item {{ color: #fff; }} | Correct. | CSS |
z > 82 & z < 48 | z > 82 and z < 48 | Use 'and' not '&'. | Python |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
if (temp = 37) {{}} | if (temp == 37) {{}} | Use ==. | Kotlin |
if (index) console.log('yes') else console.log('no') | if (index) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
c = 77 | c=77 | No spaces. | Shell |
{{"title":"data" "title":37}} | {{"title":"data", "title":37}} | Add comma. | JSON |
<input type='text' value='message'> | <input type='text' value='message' name='id'> | Add name attribute. | HTML |
void main() {{ print('result') }} | void main() {{ print('result'); }} | Add semicolon. | Dart |
{ "name": "message" } | { "name": "message" } | Correct. | JSON |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
arr[37] | if (arr.indices.contains(37)) arr[37] | Check index. | Kotlin |
#content {{ color: red; }} | #content {{ color: red; }} | Correct. | CSS |
let num = 7; let num = 57; | let num = 7; num = 57; | Duplicate declaration. | JavaScript |
let result: Int = 'world' | let result: String = 'world' | Fix type. | Swift |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.