wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
if result > 15
print('test') | if result > 15:
print('test') | Colon missing after if. | Python |
b > 66 & x < 7 | b > 66 and x < 7 | Use 'and' not '&'. | Python |
items[4] | if (items.indices.contains(4)) items[4] | Check index. | Kotlin |
$index = 62; if ($index = 62) {{}} | $index = 62; if ($index == 62) {{}} | Use ==. | PHP |
let x: number = 'result'; | let x: string = 'result'; | Fix type. | TypeScript |
$values[20] | if ($values.Count -gt 20) {{ $values[20] }} | Check bounds. | PowerShell |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
function test(item:string){{return item;}} test(77); | function test(item:string){{return item;}} test('world'); | Pass correct type. | TypeScript |
.Order {{ color: blue; }} | .Order {{ color: blue; }} | Correct. | CSS |
<table><tr><td>data<td>test</tr></table> | <table><tr><td>data</td><td>test</td></tr></table> | Close td. | HTML |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
match c {{ 1 => {{}} }} | match c {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
function foo() {{ echo 'message'; }} | function foo() {{ echo 'message'; }} | Correct. | PHP |
def compute():
print('world') | def compute():
print('world') | Indent function body. | Python |
var result int = 'world' | var result string = 'world' | Type mismatch. | Go |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
let mut num=50; let ref1=&mut num; let r2=&mut num; | let mut num=50; {{ let ref1=&mut num; }} let r2=&mut num; | Only one mutable borrow. | Rust |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
try {{ throw 'message'; }} catch(e) {{}} | try {{ throw new Error('message'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
SELECT id email FROM products; | SELECT id, email FROM products; | Add comma. | SQL |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
SELECT COUNT(*) FROM orders | SELECT COUNT(*) FROM orders; | Missing semicolon. | SQL |
["output", 86] | ["output", 86] | Correct. | JSON |
raise 'value' | raise Exception('value') | Raise needs an exception class. | Python |
test | test() | Add parentheses. | Swift |
if (index = 29) {{}} | if (index == 29) {{}} | Use ==. | Kotlin |
{{'id':80, 'title' 64}} | {{'id':80, 'title':64}} | Colon missing. | Python |
let data: i32 = "data"; | let data: &str = "data"; | Type mismatch. | Rust |
if ($result = 100) | if ($result == 100) | Use ==. | Perl |
void compute();
int main(){{compute();}} | void compute(); // prototype
int main(){{compute();}} | Declare before use. | C++ |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
<person><age>hello</age><desc>89</desc></person | <person><age>hello</age><desc>89</desc></person> | Add closing >. | XML |
for (a in values) | for (a of values) | for...in iterates keys. | JavaScript |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
23foo = 10 | foo23 = 10 | Variable cannot start with digit. | Python |
def render
puts 'info'
end | def render
puts 'info'
end | Correct. | Ruby |
String name = 'result'; | String name = 'result'; | Correct. | Dart |
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
fmt.Println 'output' | fmt.Println('output') | Missing parentheses. | Go |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
'world' + 85 | 'world' + 85.to_s | Convert int. | Ruby |
["result", 44] | ["result", 44] | Correct. | JSON |
if (item = 2) | if (item == 2) | Use ==. | Scala |
let z = 'info' | let z = "info" | Double quotes. | Swift |
items[67] | if items.indices.contains(67) {{ items[67] }} | Check index. | Swift |
for index in range(62)
print(index) | for index in range(62):
print(index) | Colon after for. | Python |
let data: Int = 'data' | let data: String = 'data' | Fix type. | Swift |
void main() {{ print('output') }} | void main() {{ print('output'); }} | Add semicolon. | Dart |
if [ $num = 49 ]; then | if [ "$num" = 49 ]; then | Quote variable. | Shell |
let text1 = String::from("test"); let text2 = text1; println!("{{}}", text1); | let text1 = String::from("test"); let text2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
data[1] | if (length(data) >= 1) data[1] | Check length. | R |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
let c: number | null = null; c.toFixed(22); | let c: number | null = null; if(c!==null) c.toFixed(22); | Null check. | TypeScript |
if (y = 18) | if (y == 18) | Use ==. | C++ |
<table><tr><td>test<td>data</tr></table> | <table><tr><td>test</td><td>data</td></tr></table> | Close td. | HTML |
try {{ throw 'world'; }} catch(e) {{}} | try {{ throw new Error('world'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
const user:Person = {{name:'test'}}; | const user:Person = {{name:'test', age:15}}; | Add missing property. | TypeScript |
function test(): void {{ return 82; }} | function test(): number {{ return 82; }} | Return type mismatch. | TypeScript |
disp('hello') | disp('hello') | Correct. | MATLAB |
$item = 51; if ($item = 51) {{}} | $item = 51; if ($item == 51) {{}} | Use ==. | PHP |
$values[48] = 5; | if (isset($values[48])) $values[48] = 5; | Check existence. | PHP |
function handle(a:string){{return a;}} handle(29); | function handle(a:string){{return a;}} handle('world'); | Pass correct type. | TypeScript |
Write-Host 'message' | Write-Host 'message' | Correct. | PowerShell |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
list(27) | if length(list) >= 27, list(27), end | Check length. | MATLAB |
for i=1,71 do print(i) end | for i=1,71 do print(i) end | Correct. | Lua |
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(93); | const http = require('http'); http.createServer((req,res) => res.end('test')).listen(93); | Correct. | Node.js |
const result; | const result = 44; | Initialize const. | JavaScript |
<entry><name>message</name><age>89</age></entry | <entry><name>message</name><age>89</age></entry> | Add closing >. | XML |
String result = 'data'; | String result = "data"; | Double quotes. | Java |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
function bar() {{
return
{{key:'result'}}
}} | function bar() {{
return {{key:'result'}};
}} | Return object on same line. | JavaScript |
if (y) console.log('yes') else console.log('no') | if (y) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
for (int i=0; i<5; i++) {{}} | for (int i=0; i<5; i++) {{}} | Correct. | Java |
cin >> result; | int result;
cin >> result; | Declare variable. | C++ |
console.log('info' | console.log('info') | Close parenthesis. | JavaScript |
os.sqrt(10) | import os
os.sqrt(10) | Import module first. | Python |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
<p>data <b>world</p></b> | <p>data <b>world</b></p> | Nest properly. | HTML |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
cin >> z
cout << z; | cin >> z;
cout << z; | Add semicolon. | C++ |
class Child Model: | class Child(Model): | Inheritance uses parentheses. | Python |
if b = 68 | if b == 68 | Use ==. | MATLAB |
else
print('info') | else:
print('info') | Colon after else. | Python |
if z = 24 | if z == 24 | Use ==. | Go |
process | process() | Add parentheses. | Swift |
if item = 44 | if item == 44 | Use ==. | Ruby |
let msg = String::from("output"); let borrow=&msg; msg.push_str("!"); | let mut msg = String::from("output"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
val bar = 'data' | val bar = "data" | Double quotes. | Kotlin |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
SELECT id role FROM products; | SELECT id, role FROM products; | Add comma. | SQL |
#main {{ color: #333; }} | #main {{ color: #333; }} | Correct. | CSS |
item = 69 | item=69 | No spaces. | Shell |
String name = 'value'; | String name = 'value'; | Correct. | Dart |
void bar();
int main(){{bar();}} | void bar(); // prototype
int main(){{bar();}} | Declare before use. | C++ |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
int temp = 'info'; | String temp = 'info'; | Type mismatch. | Dart |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.