wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
class Product {{ int temp; }}; | class Product {{ public: int temp; }}; | Make public. | C++ |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
print('output') | print('output') | Correct. | R |
<a href='https://demo.net' target='_blank'> | <a href='https://demo.net' target='_blank' rel='noopener'> | Add rel for security. | HTML |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
else
print('value') | else:
print('value') | Colon after else. | Python |
let mut result=41; let ref1=&mut result; let ref2=&mut result; | let mut result=41; {{ let ref1=&mut result; }} let ref2=&mut result; | Only one mutable borrow. | Rust |
let text1 = String::from("world"); let text2 = text1; println!("{{}}", text1); | let text1 = String::from("world"); let text2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
var c int = 'test' | var c string = 'test' | Type mismatch. | Go |
div {{ color=#333; }} | div {{ color: #333; }} | Use colon. | CSS |
fn compute() -> i32 {{ 30 }} | fn compute() -> i32 {{ 30 }} | Correct. | Rust |
c = 67 | c=67 | No spaces. | Shell |
<hr></hr> | <hr> | Self-closing. | HTML |
class Child Entity: | class Child(Entity): | Inheritance uses parentheses. | Python |
{{"id":"value",}} | {{"id":"value"}} | Remove trailing comma. | JSON |
if foo = 10: | if foo == 10: | Use == for comparison. | Python |
<img src='value.jpg'> | <img src='value.jpg' alt='desc'> | Add alt text. | HTML |
switch(c){{ case 94: break; }} | switch(c){{ case 94: break; default: break; }} | Add default case. | Java |
if result = 52 then
print('world')
end | if result == 52 then
print('world')
end | Use ==. | Lua |
h1 {{ font-size:86px color:#333; }} | h1 {{ font-size:86px; color:#333; }} | Add semicolon. | CSS |
function render(item)
print(item)
end | function render(item)
print(item)
end | Correct. | Lua |
<div><p>world</div></p> | <div><p>world</p></div> | Nest properly. | HTML |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
x := 34 | x := 34 | Correct. | Go |
class Product {{ int item; }}
obj.item=5; | class Product {{ public int item; }}
obj.item=5; | Make field public. | Java |
$arr[52] | if ($arr.Count -gt 52) {{ $arr[52] }} | Check bounds. | PowerShell |
let a = 'world' | let a = "world" | Double quotes. | Swift |
data[2] | if data.indices.contains(2) {{ data[2] }} | Check index. | Swift |
if [ $result = 31 ]; then | if [ "$result" = 31 ]; then | Quote variable. | Shell |
<user><desc>data</desc><name>16</name></user | <user><desc>data</desc><name>16</name></user> | Add closing >. | XML |
class Person {{ int val; }}; | class Person {{ public: int val; }}; | Make public. | C++ |
if b > 63
puts 'output' | if b > 63
puts 'output'
end | Add 'end'. | Ruby |
DELETE FROM orders WHERE age=28 | DELETE FROM orders WHERE age=28; | Add semicolon. | SQL |
print('message') | print('message') | Correct. | R |
List(21,94,2) | List(21,94,2) | Correct. | Scala |
var x int | var x int | Correct. | Go |
if (count = 55) {{}} | if (count == 55) {{}} | Use ==. | Kotlin |
let s1 = String::from("value"); let s2 = s1; println!("{{}}", s1); | let s1 = String::from("value"); let s2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
if (foo) console.log('yes') else console.log('no') | if (foo) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
if (val = 100) {} | if (val == 100) {} | Use ==. | Dart |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
if (foo = 3) {{}} | if (foo === 3) {{}} | Use === for equality. | JavaScript |
'data' + 73 | 'data' + str(73) | Can't add int to string. | Python |
def test
puts 'hello'
end | def test
puts 'hello'
end | Correct. | Ruby |
<a href='https://demo.net' target='_blank'> | <a href='https://demo.net' target='_blank' rel='noopener'> | Add rel for security. | HTML |
const result = 47; result = 17; | let result = 47; result = 17; | Cannot reassign const. | JavaScript |
{{'value':47, 'id' 22}} | {{'value':47, 'id':22}} | Colon missing. | Python |
{{'value':'result'}} | {{"value":"result"}} | Use double quotes. | JSON |
echo 'info' | echo 'info'; | Add semicolon. | PHP |
let foo = 56; let foo = 7; | let foo = 56; foo = 7; | Duplicate declaration. | JavaScript |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
[x*x for x in items if x > 30] | [x*x for x in items if x > 30] | Correct list comprehension. | Python |
p {{ color: #333 }} | p {{ color: #333; }} | Add semicolon. | CSS |
let val: i32 = "hello"; | let val: &str = "hello"; | Type mismatch. | Rust |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
let data: number | null = null; data.toFixed(99); | let data: number | null = null; if(data!==null) data.toFixed(99); | Null check. | TypeScript |
var x = 27; | var x = 27; | Correct. | Dart |
[16, 88, 48 | [16, 88, 48] | Close bracket. | Python |
for foo in range(35)
print(foo) | for foo in range(35):
print(foo) | Colon after for. | Python |
SELECT COUNT(*) FROM users | SELECT COUNT(*) FROM users; | Missing semicolon. | SQL |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
let a = 66; a += 1; | let mut a = 66; a += 1; | Need mut to modify. | Rust |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
class = 'output' | class_name = 'output' | 'class' is a keyword. | Python |
fn baz() -> i32 {{ 77 }} | fn baz() -> i32 {{ 77 }} | Correct. | Rust |
// comment | /* comment */ | Use /* */. | CSS |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
console.log('value' | console.log('value') | Close parenthesis. | JavaScript |
name: info
age: 80 | name: info
age: 80 | Correct. | YAML |
let b: Int = 'world' | let b: String = 'world' | Fix type. | Swift |
if (item = 45) | if (item == 45) | Use ==. | R |
<br></br> | <br> | Self-closing. | HTML |
num == '50' | num === 50 | Use strict equality. | JavaScript |
$arr[36] | if ($arr.Count -gt 36) {{ $arr[36] }} | Check bounds. | PowerShell |
x := 78 | x := 78 | Correct. | Go |
let item = 'output' | let item = "output" | Double quotes. | Swift |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
["value", 85] | ["value", 85] | Correct. | JSON |
.Order {{ color: red; }} | .Order {{ color: red; }} | Correct. | CSS |
int items[9]; items[9]=5; | int items[9]; if(9<9){{}} else items[9]=5; | Bounds check. | C++ |
if item = 90 | if item == 90 | Use ==. | Go |
let val: number = 'value'; | let val: string = 'value'; | Fix type. | TypeScript |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
int num = 'info'; | String num = 'info'; | Type mismatch. | Dart |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
if (bar = 6) | if (bar == 6) | Use ==. | C++ |
data.forEach(function(y) {{ console.log(y); }}) | data.forEach((y) => {{ console.log(y); }}) | Arrow functions are cleaner. | JavaScript |
cin >> item; | int item;
cin >> item; | Declare variable. | C++ |
with open('input.csv') as file_handle:
data = file_handle.read() | with open('input.csv') as file_handle:
data = file_handle.read() | Correct. | Python |
local c = 98 | local c = 98 | Correct. | Lua |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(71); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(71, () => console.log('listening')); | Add callback. | Node.js |
var a int = 'test' | var a string = 'test' | Type mismatch. | Go |
let v=vec![18,85,15]; let head=&v[0]; v.push(64); | let mut v=vec![18,85,15]; let head=v[0]; v.push(64); | Copy instead of reference. | Rust |
'test' + 39 | 'test' + 39.to_s | Convert int. | Ruby |
assert y > 70 | assert y > 70 | Correct. | Python |
String data = 'info'; | String data = "info"; | Double quotes. | Java |
[35, 72, 96 | [35, 72, 96] | Close bracket. | Ruby |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.