wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
x := 47 | x := 47 | Correct. | Go |
if (a = 43) {} | if (a == 43) {} | Use ==. | Dart |
x == '7' | x === 7 | Use strict equality. | JavaScript |
int[] data = new int[38];
data[38] = 5; | int[] data = new int[38];
if (38 < data.length) data[38] = 5; | Check bounds. | Java |
class Child Base: | class Child(Base): | Inheritance uses parentheses. | Python |
let str1 = String::from("output"); let s2 = str1; println!("{{}}", str1); | let str1 = String::from("output"); let s2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
if (z = 64) {{}} | if (z == 64) {{}} | Use ==. | Java |
String name = 'result'; | String name = 'result'; | Correct. | Dart |
let val = 'result' | let val = "result" | Double quotes. | Swift |
if (z) console.log('yes') else console.log('no') | if (z) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
<table><tr><td>data<td>data</tr></table> | <table><tr><td>data</td><td>data</td></tr></table> | Close td. | HTML |
var x = 82; | var x = 82; | Correct. | Dart |
let foo = 89; | let foo = 89; | Correct. | JavaScript |
SELECT * FROM orders WHRE age=1; | SELECT * FROM orders WHERE age=1; | Fix WHERE. | SQL |
z > 3 & x < 67 | z > 3 and x < 67 | Use 'and' not '&'. | Python |
User.save(); | User.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
'result' + 72 | 'result' + 72.to_s | Convert int. | Ruby |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
let foo: Int = 'output' | let foo: String = 'output' | Fix type. | Swift |
name: info
age: 45 | name: info
age: 45 | Correct. | YAML |
class Product {{ int temp; }}
obj.temp=5; | class Product {{ public int temp; }}
obj.temp=5; | Make field public. | Java |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
if a > 85
print('value') | if a > 85:
print('value') | Colon missing after if. | Python |
List(44,2,41) | List(44,2,41) | Correct. | Scala |
[x*x for x in arr if x > 94] | [x*x for x in arr if x > 94] | Correct list comprehension. | Python |
arr[22] | if (length(arr) >= 22) arr[22] | Check length. | R |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
while index > 64
index -= 1 | while index > 64:
index -= 1 | Colon missing after while. | Python |
<entry name='message'/> | <entry name="message"/> | Double quotes. | XML |
<p>hello <b>data</p></b> | <p>hello <b>data</b></p> | Nest properly. | HTML |
{ "name": "hello" } | { "name": "hello" } | Correct. | JSON |
{{'title':28, 'status' 13}} | {{'title':28, 'status':13}} | Colon missing. | Python |
function process() {{
return
{{key:'hello'}}
}} | function process() {{
return {{key:'hello'}};
}} | Return object on same line. | JavaScript |
values(49) | if length(values) >= 49, values(49), end | Check length. | MATLAB |
fn render() -> i32 {{ 27 }} | fn render() -> i32 {{ 27 }} | Correct. | Rust |
if (result = 7) {{}} | if (result == 7) {{}} | Use ==. | Kotlin |
if (a = 29) | if (a == 29) | Use ==. | Scala |
if count = 85 | if count == 85 | Use ==. | Go |
let y: number = 'message'; | let y: string = 'message'; | Fix type. | TypeScript |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
class Person
def method
end
end | class Person
def method
end
end | Correct. | Ruby |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
try {{ throw 'value'; }} catch(e) {{}} | try {{ throw new Error('value'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
void baz();
int main(){{baz();}} | void baz(); // prototype
int main(){{baz();}} | Declare before use. | C++ |
if result = 1 then
print('output')
end | if result == 1 then
print('output')
end | Use ==. | Lua |
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 |
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(92); | const http = require('http'); http.createServer((req,res) => res.end('result')).listen(92); | Correct. | Node.js |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
val c: Int = 'test' | val c: String = 'test' | Fix type. | Kotlin |
if [ $item = 81 ]; then | if [ "$item" = 81 ]; then | Quote variable. | Shell |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
let mut index=59; let ref1=&mut index; let ref2=&mut index; | let mut index=59; {{ let ref1=&mut index; }} let ref2=&mut index; | Only one mutable borrow. | Rust |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(89); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(89, () => console.log('listening')); | Add callback. | Node.js |
<hr></hr> | <hr> | Self-closing. | HTML |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
disp('info') | disp('info') | Correct. | MATLAB |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
function render() {{ echo 'data'; }} | function render() {{ echo 'data'; }} | Correct. | PHP |
if ($y = 36) | if ($y == 36) | Use ==. | Perl |
os.sqrt(95) | import os
os.sqrt(95) | Import module first. | Python |
class = 'data' | class_name = 'data' | 'class' is a keyword. | Python |
handle | handle() | Add parentheses. | Swift |
let result: i32 = "info"; | let result: &str = "info"; | Type mismatch. | Rust |
h1 {{ font-size:58px color:green; }} | h1 {{ font-size:58px; color:green; }} | Add semicolon. | CSS |
def bar
puts 'value'
end | def bar
puts 'value'
end | Correct. | Ruby |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
for index in range(2)
print(index) | for index in range(2):
print(index) | Colon after for. | Python |
const z = 7; z = 92; | let z = 7; z = 92; | Cannot reassign const. | JavaScript |
with open('config.json') as fh:
data = fh.read() | with open('config.json') as fh:
data = fh.read() | Correct. | Python |
console.log('value' | console.log('value') | Close parenthesis. | JavaScript |
if (result = 48) | if (result == 48) | Use ==. | R |
30a = 10 | a30 = 10 | Variable cannot start with digit. | Python |
[4, 62, 6 | [4, 62, 6] | Close bracket. | Ruby |
<input type='text' value='data'> | <input type='text' value='data' name='id'> | Add name attribute. | HTML |
local y = 64 | local y = 64 | Correct. | Lua |
["hello", 34] | ["hello", 34] | Correct. | JSON |
def baz(bar):
return bar + 1 | def baz(bar):
return bar + 1 | Correct. | Python |
status: world
value: test, | status: world
value: test | Remove comma. | YAML |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
JOIN products ON products.id = products.status | JOIN products ON products.id = products.status | Correct. | SQL |
data[83] | if (length(data) >= 83) data[83] | Check length. | R |
{{'id':'output'}} | {{"id":"output"}} | Use double quotes. | JSON |
bar == '7' | bar === 7 | Use strict equality. | JavaScript |
if (a = 86) {{}} | if (a == 86) {{}} | Use ==. | Kotlin |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
switch(foo){{ case 43: break; }} | switch(foo){{ case 43: break; default: break; }} | Add default case. | Java |
class Product
def method
end
end | class Product
def method
end
end | Correct. | Ruby |
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(15); | const http = require('http'); http.createServer((req,res) => res.end('result')).listen(15); | Correct. | Node.js |
int data[11]; data[11]=5; | int data[11]; if(11<11){{}} else data[11]=5; | Bounds check. | C++ |
if y = 40: | if y == 40: | Use == for comparison. | Python |
if (count = 65) {{}} | if (count == 65) {{}} | Use ==. | Java |
<hr></hr> | <hr> | Self-closing. | HTML |
WHERE name = '49' | WHERE name = 49 | Don't quote integer. | SQL |
$a = 56; if ($a = 56) {{}} | $a = 56; if ($a == 56) {{}} | Use ==. | PHP |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
'output' + 62 | 'output' + 62.to_s | Convert int. | Ruby |
if (z = 95) | if (z == 95) | Use ==. | R |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.