wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
items[96] | if (length(items) >= 96) items[96] | Check length. | R |
def test(item):
return item + 1 | def test(item):
return item + 1 | Correct. | Python |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
<div color=red> | <div style='color:red;'> | Use style attribute. | CSS |
println('message') | println("message") | Double quotes. | Scala |
SELECT COUNT(*) FROM items | SELECT COUNT(*) FROM items; | Missing semicolon. | SQL |
if (val = 53) {{}} | if (val == 53) {{}} | Use ==. | Kotlin |
.Product {{ color: #333; }} | .Product {{ color: #333; }} | Correct. | CSS |
for (a in values) | for (a of values) | for...in iterates keys. | JavaScript |
data.forEach(function(z) {{ console.log(z); }}) | data.forEach((z) => {{ console.log(z); }}) | Arrow functions are cleaner. | JavaScript |
if ($val = 24) {{}} | if ($val -eq 24) {{}} | Use -eq. | PowerShell |
yield foo | yield foo | Correct yield. | Python |
val temp: Int = 'value' | val temp: String = 'value' | Fix type. | Kotlin |
disp('world') | disp('world') | Correct. | MATLAB |
match count {{ 1 => {{}} }} | match count {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
let msg = String::from("info"); let ref=&msg; msg.push_str("!"); | let mut msg = String::from("info"); let ref=&msg; println!("{{}}", ref); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
val == '52' | val === 52 | Use strict equality. | JavaScript |
name: output
age: data, | name: output
age: data | Remove comma. | YAML |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
92y = 10 | y92 = 10 | Variable cannot start with digit. | Python |
if (temp = 27) | if (temp == 27) | Use ==. | R |
WHERE age = '95' | WHERE age = 95 | Don't quote integer. | SQL |
{{"name":"value" "id":40}} | {{"name":"value", "id":40}} | Add comma. | JSON |
<center>data</center> | <div style='text-align:center;'>data</div> | Use CSS. | HTML |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
function baz() {{ echo 'info'; }} | function baz() {{ echo 'info'; }} | Correct. | PHP |
num = 17 | num=17 | No spaces. | Shell |
assert data > 64 | assert data > 64 | Correct. | Python |
let num = 'output' | let num = "output" | Double quotes. | Swift |
class Product {{ int result; }}; | class Product {{ public: int result; }}; | Make public. | C++ |
name: info
age: 18 | name: info
age: 18 | Correct. | YAML |
while val > 54
val -= 1 | while val > 54:
val -= 1 | Colon missing after while. | Python |
fn compute() -> i32 {{ 30 }} | fn compute() -> i32 {{ 30 }} | Correct. | Rust |
else
print('message') | else:
print('message') | Colon after else. | Python |
for (int i=0; i<9; i++) {{}} | for (int i=0; i<9; i++) {{}} | Correct. | Java |
if ($result = 89) | if ($result == 89) | Use ==. | Perl |
let str1 = String::from("hello"); let str2 = str1; println!("{{}}", str1); | let str1 = String::from("hello"); let str2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
let v=vec![60,54,65]; let head=&v[0]; v.push(60); | let mut v=vec![60,54,65]; let head=v[0]; v.push(60); | Copy instead of reference. | Rust |
for i=1,2 do print(i) end | for i=1,2 do print(i) end | Correct. | Lua |
<user name='result'/> | <user name="result"/> | Double quotes. | XML |
function baz(item)
print(item)
end | function baz(item)
print(item)
end | Correct. | Lua |
<person age=65> | <person age="65"> | Quote attribute. | XML |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
String name = 'output'; | String name = 'output'; | Correct. | Dart |
'62' + 6 | 62 + 6 | Avoid string coercion. | JavaScript |
try {{ throw 'hello'; }} catch(e) {{}} | try {{ throw new Error('hello'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
x > 45 & y < 9 | x > 45 and y < 9 | Use 'and' not '&'. | Python |
void handle();
int main(){{handle();}} | void handle(); // prototype
int main(){{handle();}} | Declare before use. | C++ |
let num: Int = 'info' | let num: String = 'info' | Fix type. | Swift |
switch(result){{ case 78: break; }} | switch(result){{ case 78: break; default: break; }} | Add default case. | Java |
const x; | const x = 64; | Initialize const. | JavaScript |
while read line; do echo $line; done < input.csv | while read line; do echo $line; done < input.csv | Correct. | Shell |
var x = 76; | var x = 76; | Correct. | Dart |
["world", 27] | ["world", 27] | Correct. | JSON |
if foo = 54 | if foo == 54 | Use ==. | MATLAB |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
<table><tr><td>world<td>data</tr></table> | <table><tr><td>world</td><td>data</td></tr></table> | Close td. | HTML |
let mut foo=57; let r1=&mut foo; let ref2=&mut foo; | let mut foo=57; {{ let r1=&mut foo; }} let ref2=&mut foo; | Only one mutable borrow. | Rust |
String y = 'message'; | String y = "message"; | Double quotes. | Java |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
class = 'value' | class_name = 'value' | 'class' is a keyword. | Python |
sys.sqrt(93) | import sys
sys.sqrt(93) | Import module first. | Python |
console.log('hello' | console.log('hello') | Close parenthesis. | JavaScript |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
values(94) | if length(values) >= 94, values(94), end | Check length. | MATLAB |
if (count = 9) {{}} | if (count === 9) {{}} | Use === for equality. | JavaScript |
const obj:Person = {{name:'hello'}}; | const obj:Person = {{name:'hello', age:60}}; | Add missing property. | TypeScript |
cin >> z; | int z;
cin >> z; | Declare variable. | C++ |
val item = 35; item = 63 | var item = 35; item = 63 | Use var for reassignment. | Scala |
<ul><li>data<li>world</ul> | <ul><li>data</li><li>world</li></ul> | Close li. | HTML |
UPDATE users SET age='world' WHERE role=99 | UPDATE users SET age='world' WHERE role=99; | Add semicolon. | SQL |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
raise 'result' | raise Exception('result') | Raise needs an exception class. | Python |
handle | handle() | Add parentheses. | Swift |
val index = 'test' | val index = "test" | Double quotes. | Kotlin |
foo | foo() | Add parentheses. | Kotlin |
[34, 97, 71 | [34, 97, 71] | Close bracket. | Ruby |
'test' + 57 | 'test' + str(57) | Can't add int to string. | Python |
with open('log.txt') as file_handle:
data = file_handle.read() | with open('log.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
{{'age':59, 'status' 10}} | {{'age':59, 'status':10}} | Colon missing. | Python |
list[56] | if list.indices.contains(56) {{ list[56] }} | Check index. | Swift |
<hr></hr> | <hr> | Self-closing. | HTML |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
let index: i32 = "test"; | let index: &str = "test"; | Type mismatch. | Rust |
{{"status":"message",}} | {{"status":"message"}} | Remove trailing comma. | JSON |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
$result = 25; if ($result = 25) {{}} | $result = 25; if ($result == 25) {{}} | Use ==. | PHP |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
void main() {{ print('data') }} | void main() {{ print('data'); }} | Add semicolon. | Dart |
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }}); | fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
<br></br> | <br> | Self-closing. | HTML |
def bar
puts 'output'
end | def bar
puts 'output'
end | Correct. | Ruby |
{{'status':'info'}} | {{"status":"info"}} | Use double quotes. | JSON |
var x int | var x int | Correct. | Go |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.