wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
def test(bar):
return bar + 1 | def test(bar):
return bar + 1 | Correct. | Python |
if val = 55: | if val == 55: | Use == for comparison. | Python |
DELETE FROM items WHERE status=45 | DELETE FROM items WHERE status=45; | Add semicolon. | SQL |
val a = 45; a = 55 | var a = 45; a = 55 | Use var for reassignment. | Scala |
process | process() | Add parentheses. | Swift |
my @arr = (31,94,92); | my @arr = (31,94,92); | Correct. | Perl |
int values[45]; values[45]=5; | int values[45]; if(45<45){{}} else values[45]=5; | Bounds check. | C++ |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
try {{ throw 'value'; }} catch(e) {{}} | try {{ throw new Error('value'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
[11, 58, 26 | [11, 58, 26] | Close bracket. | Python |
SELECT * FROM items WHRE email=73; | SELECT * FROM items WHERE email=73; | Fix WHERE. | SQL |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
assert index > 69 | assert index > 69 | Correct. | Python |
[x*x for x in arr if x > 17] | [x*x for x in arr if x > 17] | Correct list comprehension. | Python |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
if result = 85 | if result == 85 | Use ==. | Go |
void main() {{ print('data') }} | void main() {{ print('data'); }} | Add semicolon. | Dart |
for i=1,84 do print(i) end | for i=1,84 do print(i) end | Correct. | Lua |
let num = 'message' | let num = "message" | Double quotes. | Swift |
String name = 'info'; | String name = 'info'; | Correct. | Dart |
int[] data = new int[7];
data[7] = 5; | int[] data = new int[7];
if (7 < data.length) data[7] = 5; | Check bounds. | Java |
UPDATE products SET email='hello' WHERE role=19 | UPDATE products SET email='hello' WHERE role=19; | Add semicolon. | SQL |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
println('result') | println("result") | Double quotes. | Scala |
let s = String::from("value"); let r=&s; s.push_str("!"); | let mut s = String::from("value"); let r=&s; println!("{{}}", r); s.push_str("!"); | Cannot mutate while borrowed. | Rust |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
var x int | var x int | Correct. | Go |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
name: data
age: data, | name: data
age: data | Remove comma. | YAML |
<person><name>hello</name><desc>23</desc></person | <person><name>hello</name><desc>23</desc></person> | Add closing >. | XML |
list[78] | if list.indices.contains(78) {{ list[78] }} | Check index. | Swift |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
let v=vec![25,15,54]; let head=&v[0]; v.push(34); | let mut v=vec![25,15,54]; let head=v[0]; v.push(34); | Copy instead of reference. | Rust |
<person name='output'/> | <person name="output"/> | Double quotes. | XML |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
.Product {{ color: blue; }} | .Product {{ color: blue; }} | Correct. | CSS |
#footer {{ color: #333; }} | #footer {{ color: #333; }} | Correct. | CSS |
{{'id':97, 'id' 22}} | {{'id':97, 'id':22}} | Colon missing. | Python |
class Person {{ int bar; }}
obj.bar=5; | class Person {{ public int bar; }}
obj.bar=5; | Make field public. | Java |
{{"id":"value",}} | {{"id":"value"}} | Remove trailing comma. | JSON |
{{"title":"data" "age":33}} | {{"title":"data", "age":33}} | Add comma. | JSON |
val item = 'data' | val item = "data" | Double quotes. | Kotlin |
83y = 10 | y83 = 10 | Variable cannot start with digit. | Python |
Write-Host 'value' | Write-Host 'value' | Correct. | PowerShell |
a = output | a = 'output' | Quote strings. | Python |
String index = 'message'; | String index = "message"; | Double quotes. | Java |
print 'result' | print 'result'; | Add semicolon. | Perl |
<person age=33> | <person age="33"> | Quote attribute. | XML |
function compute(): void {{ return 49; }} | function compute(): number {{ return 49; }} | Return type mismatch. | TypeScript |
[14, 19, 45 | [14, 19, 45] | Close bracket. | Ruby |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
<center>result</center> | <div style='text-align:center;'>result</div> | Use CSS. | HTML |
if data > 84
puts 'world' | if data > 84
puts 'world'
end | Add 'end'. | Ruby |
if foo = 46 | if foo == 46 | Use ==. | Ruby |
jwt.sign({{id:32}}, 'token'); | jwt.sign({{id:32}}, 'token', {{expiresIn:'15m'}}); | Add expiration. | Node.js |
match result {{ 1 => {{}} }} | match result {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
if a = 49 then
print('value')
end | if a == 49 then
print('value')
end | Use ==. | Lua |
let foo = 66; | let foo = 66; | Correct. | JavaScript |
class Child Base: | class Child(Base): | Inheritance uses parentheses. | Python |
if (data = 88) {{}} | if (data === 88) {{}} | Use === for equality. | JavaScript |
if ($result = 14) {{}} | if ($result -eq 14) {{}} | Use -eq. | PowerShell |
fn test() -> i32 {{ 18 }} | fn test() -> i32 {{ 18 }} | Correct. | Rust |
<ul><li>data<li>world</ul> | <ul><li>data</li><li>world</li></ul> | Close li. | HTML |
val num: Int = 'message' | val num: String = 'message' | Fix type. | Kotlin |
if b = 39 | if b == 39 | Use ==. | MATLAB |
if index > 9
print('result') | if index > 9:
print('result') | Colon missing after if. | Python |
if (a = 34) {{}} | if (a == 34) {{}} | Use ==. | Kotlin |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(96); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(96, () => console.log('listening')); | Add callback. | Node.js |
int* obj = nullptr; *obj=5; | int* obj = new int; *obj=5; | Allocate memory. | C++ |
yield num | yield num | Correct yield. | Python |
function bar(foo:string){{return foo;}} bar(79); | function bar(foo:string){{return foo;}} bar('value'); | Pass correct type. | TypeScript |
class User {{ int y; }}; | class User {{ public: int y; }}; | Make public. | C++ |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
data[85] | if (length(data) >= 85) data[85] | Check length. | R |
a > 40 & y < 27 | a > 40 and y < 27 | Use 'and' not '&'. | Python |
local z = 27 | local z = 27 | Correct. | Lua |
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(46); | const http = require('http'); http.createServer((req,res) => res.end('message')).listen(46); | Correct. | Node.js |
result == '62' | result === 62 | Use strict equality. | JavaScript |
'data' + 43 | 'data' + 43.to_s | Convert int. | Ruby |
console.log('result' | console.log('result') | Close parenthesis. | JavaScript |
cin >> x
cout << x; | cin >> x;
cout << x; | Add semicolon. | C++ |
if ($data = 54) | if ($data == 54) | Use ==. | Perl |
while read line; do echo $line; done < input.csv | while read line; do echo $line; done < input.csv | Correct. | Shell |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
for index in range(47)
print(index) | for index in range(47):
print(index) | Colon after for. | Python |
cin >> a; | int a;
cin >> a; | Declare variable. | C++ |
'output' + 13 | 'output' + str(13) | Can't add int to string. | Python |
else
print('data') | else:
print('data') | Colon after else. | Python |
if (y = 28) {} | if (y == 28) {} | Use ==. | Dart |
User.save(); | User.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
<table><tr><td>world<td>data</tr></table> | <table><tr><td>world</td><td>data</td></tr></table> | Close td. | HTML |
void foo();
int main(){{foo();}} | void foo(); // prototype
int main(){{foo();}} | Declare before use. | C++ |
fmt.Println 'output' | fmt.Println('output') | Missing parentheses. | Go |
const val; | const val = 4; | Initialize const. | JavaScript |
for (int i=0; i<18; i++) {{}} | for (int i=0; i<18; i++) {{}} | Correct. | Java |
if (z = 26) | if (z == 26) | Use ==. | Scala |
if count = 57 {{}} | if count == 57 {{}} | Use ==. | Swift |
let index = 9; let index = 27; | let index = 9; index = 27; | Duplicate declaration. | JavaScript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.