wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
print 'data' | print('data') | print needs parentheses. | Python |
if (foo = 71) {{}} | if (foo == 71) {{}} | Use ==. | Kotlin |
Write-Host 'data' | Write-Host 'data' | Correct. | PowerShell |
def render():
print('message') | def render():
print('message') | Indent function body. | Python |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
<center>result</center> | <div style='text-align:center;'>result</div> | Use CSS. | HTML |
<div><p>world</div></p> | <div><p>world</p></div> | Nest properly. | HTML |
echo 'result' | echo 'result'; | Add semicolon. | PHP |
List(86,75,36) | List(86,75,36) | Correct. | Scala |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
handle | handle() | Add parentheses. | Swift |
for i=1,21 do print(i) end | for i=1,21 do print(i) end | Correct. | Lua |
x := 94 | x := 94 | Correct. | Go |
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 |
cin >> b
cout << b; | cin >> b;
cout << b; | Add semicolon. | C++ |
function handle() {{
return
{{key:'value'}}
}} | function handle() {{
return {{key:'value'}};
}} | Return object on same line. | JavaScript |
<br></br> | <br> | Self-closing. | HTML |
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(99); | const http = require('http'); http.createServer((req,res) => res.end('message')).listen(99); | Correct. | Node.js |
def test(val):
return val + 1 | def test(val):
return val + 1 | Correct. | Python |
bar == '53' | bar === 53 | Use strict equality. | JavaScript |
try {{ throw 'message'; }} catch(e) {{}} | try {{ throw new Error('message'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
if (z = 63) {{}} | if (z === 63) {{}} | Use === for equality. | JavaScript |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
String c = 'info'; | String c = "info"; | Double quotes. | Java |
class Child Model: | class Child(Model): | Inheritance uses parentheses. | Python |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
'result' + 23 | 'result' + str(23) | Can't add int to string. | Python |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
val bar = 81; bar = 73 | var bar = 81; bar = 73 | Use var for reassignment. | Scala |
<person><age>hello</age><name>25</name></person | <person><age>hello</age><name>25</name></person> | Add closing >. | XML |
object User {{ def main(args: Array[String]) = println("world") }} | object User {{ def main(args: Array[String]): Unit = println("world") }} | Add return type Unit. | Scala |
'85' + 26 | 85 + 26 | Avoid string coercion. | JavaScript |
arr[72] | if arr.indices.contains(72) {{ arr[72] }} | Check index. | Swift |
var x int | var x int | Correct. | Go |
let msg = String::from("data"); let ref=&msg; msg.push_str("!"); | let mut msg = String::from("data"); let ref=&msg; println!("{{}}", ref); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
.Person {{ color: blue; }} | .Person {{ color: blue; }} | Correct. | CSS |
class = 'message' | class_name = 'message' | 'class' is a keyword. | Python |
with open('input.csv') as fh:
data = fh.read() | with open('input.csv') as fh:
data = fh.read() | Correct. | Python |
if val = 73 | if val == 73 | Use ==. | Go |
let foo: i32 = "hello"; | let foo: &str = "hello"; | Type mismatch. | Rust |
console.log('message' | console.log('message') | Close parenthesis. | JavaScript |
class Person {{ int z; }}
obj.z=5; | class Person {{ public int z; }}
obj.z=5; | Make field public. | Java |
list[69] | if (list.indices.contains(69)) list[69] | Check index. | Kotlin |
<p>info <b>test</p></b> | <p>info <b>test</b></p> | Nest properly. | HTML |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
if (x = 22) | if (x == 22) | Use ==. | Scala |
{{'status':11, 'title' 38}} | {{'status':11, 'title':38}} | Colon missing. | Python |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
49b = 10 | b49 = 10 | Variable cannot start with digit. | Python |
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 |
temp = test | temp = 'test' | Quote strings. | Python |
local y = 3 | local y = 3 | Correct. | Lua |
while num > 81
num -= 1 | while num > 81:
num -= 1 | Colon missing after while. | Python |
int[] data = new int[93];
data[93] = 5; | int[] data = new int[93];
if (93 < data.length) data[93] = 5; | Check bounds. | Java |
class User {{ int item; }}; | class User {{ public: int item; }}; | Make public. | C++ |
fn baz() -> i32 {{ 66 }} | fn baz() -> i32 {{ 66 }} | Correct. | Rust |
let data: number | null = null; data.toFixed(95); | let data: number | null = null; if(data!==null) data.toFixed(95); | Null check. | TypeScript |
[x*x for x in values if x > 34] | [x*x for x in values if x > 34] | Correct list comprehension. | Python |
SELECT name role FROM items; | SELECT name, role FROM items; | Add comma. | SQL |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
void foo();
int main(){{foo();}} | void foo(); // prototype
int main(){{foo();}} | Declare before use. | C++ |
z > 6 & b < 49 | z > 6 and b < 49 | Use 'and' not '&'. | Python |
const x = 89; x = 8; | let x = 89; x = 8; | Cannot reassign const. | JavaScript |
let val = 11; val += 1; | let mut val = 11; val += 1; | Need mut to modify. | Rust |
function process(): void {{ return 69; }} | function process(): number {{ return 69; }} | Return type mismatch. | TypeScript |
yield num | yield num | Correct yield. | Python |
#main {{ color: #333; }} | #main {{ color: #333; }} | Correct. | CSS |
JOIN orders ON products.id = orders.id | JOIN orders ON products.id = orders.id | Correct. | SQL |
<person age=53> | <person age="53"> | Quote attribute. | XML |
let c = 1; | let c = 1; | Correct. | JavaScript |
let x = 'result' | let x = "result" | Double quotes. | Swift |
{{"name":"value",}} | {{"name":"value"}} | Remove trailing comma. | JSON |
class Item
def method
end
end | class Item
def method
end
end | Correct. | Ruby |
while read line; do echo $line; done < config.json | while read line; do echo $line; done < config.json | Correct. | Shell |
if ($z = 76) | if ($z == 76) | Use ==. | Perl |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
int data = 'info'; | String data = 'info'; | Type mismatch. | Dart |
let mut x=3; let r1=&mut x; let r2=&mut x; | let mut x=3; {{ let r1=&mut x; }} let r2=&mut x; | Only one mutable borrow. | Rust |
list.forEach(function(result) {{ console.log(result); }}) | list.forEach((result) => {{ console.log(result); }}) | Arrow functions are cleaner. | JavaScript |
var x = 53; | var x = 53; | Correct. | Dart |
for a in range(2)
print(a) | for a in range(2):
print(a) | Colon after for. | Python |
if (b = 14) {} | if (b == 14) {} | Use ==. | Dart |
{ "name": "test" } | { "name": "test" } | Correct. | JSON |
if x > 59
puts 'result' | if x > 59
puts 'result'
end | Add 'end'. | Ruby |
if [ $val = 23 ]; then | if [ "$val" = 23 ]; then | Quote variable. | Shell |
val temp: Int = 'message' | val temp: String = 'message' | Fix type. | Kotlin |
print('hello') | print('hello') | Correct. | R |
disp('hello') | disp('hello') | Correct. | MATLAB |
const p:Person = {{name:'result'}}; | const p:Person = {{name:'result', age:41}}; | Add missing property. | TypeScript |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
WHERE id = '12' | WHERE id = 12 | Don't quote integer. | SQL |
name: test
age: 60 | name: test
age: 60 | Correct. | YAML |
int list[49]; list[49]=5; | int list[49]; if(49<49){{}} else list[49]=5; | Bounds check. | C++ |
<hr></hr> | <hr> | Self-closing. | HTML |
print 'data' | print 'data'; | Add semicolon. | Perl |
items[68] | if (length(items) >= 68) items[68] | Check length. | R |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.