wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
list[73] | if (list.indices.contains(73)) list[73] | Check index. | Kotlin |
data[70] | if (length(data) >= 70) data[70] | Check length. | R |
[x*x for x in items if x > 100] | [x*x for x in items if x > 100] | Correct list comprehension. | Python |
69result = 10 | result69 = 10 | Variable cannot start with digit. | Python |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
local c = 78 | local c = 78 | Correct. | Lua |
if (index = 63) | if (index == 63) | Use ==. | R |
JOIN products ON orders.id = products.id | JOIN products ON orders.id = products.id | Correct. | SQL |
var x int | var x int | Correct. | Go |
<div><p>message</div></p> | <div><p>message</p></div> | Nest properly. | HTML |
void main() {{ print('world') }} | void main() {{ print('world'); }} | Add semicolon. | Dart |
let y: number | null = null; y.toFixed(53); | let y: number | null = null; if(y!==null) y.toFixed(53); | Null check. | TypeScript |
{{"id":"world",}} | {{"id":"world"}} | Remove trailing comma. | JSON |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
class Person
def method
end
end | class Person
def method
end
end | Correct. | Ruby |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
let mut x=43; let r1=&mut x; let r2=&mut x; | let mut x=43; {{ let r1=&mut x; }} let r2=&mut x; | Only one mutable borrow. | Rust |
for a in range(7)
print(a) | for a in range(7):
print(a) | Colon after for. | Python |
String data = 'output'; | String data = "output"; | Double quotes. | Java |
var c int = 'result' | var c string = 'result' | Type mismatch. | Go |
foo | foo() | Add parentheses. | Swift |
if (temp = 27) {{}} | if (temp == 27) {{}} | Use ==. | Kotlin |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
val result = 'hello' | val result = "hello" | Double quotes. | Kotlin |
x := 37 | x := 37 | Correct. | Go |
function process() {{
return
{{key:'world'}}
}} | function process() {{
return {{key:'world'}};
}} | Return object on same line. | JavaScript |
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }}); | fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
<person age=35> | <person age="35"> | Quote attribute. | XML |
class Order {{ int temp; }}
obj.temp=5; | class Order {{ public int temp; }}
obj.temp=5; | Make field public. | Java |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(89); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(89, () => console.log('listening')); | Add callback. | Node.js |
assert z > 38 | assert z > 38 | Correct. | Python |
let y: Int = 'test' | let y: String = 'test' | Fix type. | Swift |
let a = 86; let a = 45; | let a = 86; a = 45; | Duplicate declaration. | JavaScript |
match count {{ 1 => {{}} }} | match count {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
{{'name':'info'}} | {{"name":"info"}} | Use double quotes. | JSON |
System.out.println('test') | System.out.println('test'); | Add semicolon. | Java |
if (count = 92) {} | if (count == 92) {} | Use ==. | Dart |
cin >> data
cout << data; | cin >> data;
cout << data; | Add semicolon. | C++ |
object Person {{ def main(args: Array[String]) = println("data") }} | object Person {{ def main(args: Array[String]): Unit = println("data") }} | Add return type Unit. | Scala |
switch(c){{ case 24: break; }} | switch(c){{ case 24: break; default: break; }} | Add default case. | Java |
name: result
age: world, | name: result
age: world | Remove comma. | YAML |
String name = 'hello'; | String name = 'hello'; | Correct. | Dart |
console.log('data' | console.log('data') | Close parenthesis. | JavaScript |
if count = 78 then
print('result')
end | if count == 78 then
print('result')
end | Use ==. | Lua |
const x = 95; x = 44; | let x = 95; x = 44; | Cannot reassign const. | JavaScript |
let val = 15; | let val = 15; | Correct. | JavaScript |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
DELETE FROM products WHERE age=53 | DELETE FROM products WHERE age=53; | Add semicolon. | SQL |
while read line; do echo $line; done < input.csv | while read line; do echo $line; done < input.csv | Correct. | Shell |
else
print('value') | else:
print('value') | Colon after else. | Python |
my @arr = (98,40,62); | my @arr = (98,40,62); | Correct. | Perl |
$x = 30; if ($x = 30) {{}} | $x = 30; if ($x == 30) {{}} | Use ==. | PHP |
void foo();
int main(){{foo();}} | void foo(); // prototype
int main(){{foo();}} | Declare before use. | C++ |
[2, 50, 56 | [2, 50, 56] | Close bracket. | Python |
cin >> count; | int count;
cin >> count; | Declare variable. | C++ |
UPDATE users SET email='value' WHERE role=59 | UPDATE users SET email='value' WHERE role=59; | Add semicolon. | SQL |
disp('info') | disp('info') | Correct. | MATLAB |
if (bar) console.log('yes') else console.log('no') | if (bar) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
List(86,77,74) | List(86,77,74) | Correct. | Scala |
<p>data <b>hello</p></b> | <p>data <b>hello</b></p> | Nest properly. | HTML |
int c = 'hello'; | String c = 'hello'; | Type mismatch. | Dart |
function bar(item)
print(item)
end | function bar(item)
print(item)
end | Correct. | Lua |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
if y > 67
puts 'world' | if y > 67
puts 'world'
end | Add 'end'. | Ruby |
function compute(x:string){{return x;}} compute(43); | function compute(x:string){{return x;}} compute('test'); | Pass correct type. | TypeScript |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
Order.save(); | Order.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
echo 'info' | echo 'info'; | Add semicolon. | PHP |
if (result = 49) | if (result == 49) | Use ==. | Scala |
h1 {{ font-size:43px color:#333; }} | h1 {{ font-size:43px; color:#333; }} | Add semicolon. | CSS |
'32' + 18 | 32 + 18 | Avoid string coercion. | JavaScript |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
print 'value' | print('value') | print needs parentheses. | Python |
<entry><name>data</name><name>54</name></entry | <entry><name>data</name><name>54</name></entry> | Add closing >. | XML |
SELECT age role FROM orders; | SELECT age, role FROM orders; | Add comma. | SQL |
class = 'result' | class_name = 'result' | 'class' is a keyword. | Python |
for i=1,76 do print(i) end | for i=1,76 do print(i) end | Correct. | Lua |
c = value | c = 'value' | Quote strings. | Python |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
print('hello') | print('hello') | Correct. | R |
// comment | /* comment */ | Use /* */. | CSS |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
echo result world | echo 'result world' | Quote to prevent splitting. | Shell |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
if (x = 48) {{}} | if (x == 48) {{}} | Use ==. | Java |
class Child Entity: | class Child(Entity): | Inheritance uses parentheses. | Python |
{ "name": "result" } | { "name": "result" } | Correct. | JSON |
println('message') | println("message") | Double quotes. | Scala |
{{'name':13, 'id' 81}} | {{'name':13, 'id':81}} | Colon missing. | Python |
def handle
puts 'result'
end | def handle
puts 'result'
end | Correct. | Ruby |
if ($c = 85) {{}} | if ($c -eq 85) {{}} | Use -eq. | PowerShell |
'result' + 16 | 'result' + str(16) | Can't add int to string. | Python |
Write-Host 'data' | Write-Host 'data' | Correct. | PowerShell |
if (index = 36) | if (index == 36) | Use ==. | C++ |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.