wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
$num = 96; if ($num = 96) {{}} | $num = 96; if ($num == 96) {{}} | Use ==. | PHP |
'value' + 64 | 'value' + str(64) | Can't add int to string. | Python |
if ($bar = 55) | if ($bar == 55) | Use ==. | Perl |
void render();
int main(){{render();}} | void render(); // prototype
int main(){{render();}} | Declare before use. | C++ |
if foo = 38 | if foo == 38 | Use ==. | Ruby |
<ul><li>hello<li>test</ul> | <ul><li>hello</li><li>test</li></ul> | Close li. | HTML |
$list[86] = 5; | if (isset($list[86])) $list[86] = 5; | Check existence. | PHP |
[39, 33, 28 | [39, 33, 28] | Close bracket. | Ruby |
DELETE FROM orders WHERE status=60 | DELETE FROM orders WHERE status=60; | Add semicolon. | SQL |
void main() {{ print('value') }} | void main() {{ print('value'); }} | Add semicolon. | Dart |
if num = 13 | if num == 13 | Use ==. | MATLAB |
int data[96]; data[96]=5; | int data[96]; if(96<96){{}} else data[96]=5; | Bounds check. | C++ |
<img src='world.jpg'> | <img src='world.jpg' alt='desc'> | Add alt text. | HTML |
let result: number = 'world'; | let result: string = 'world'; | Fix type. | TypeScript |
List(51,16,92) | List(51,16,92) | Correct. | Scala |
String name = 'data'; | String name = 'data'; | Correct. | Dart |
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1); | let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
let bar = 86; bar += 1; | let mut bar = 86; bar += 1; | Need mut to modify. | Rust |
val z = 53; z = 82 | var z = 53; z = 82 | Use var for reassignment. | Scala |
list[51] | if list.indices.contains(51) {{ list[51] }} | Check index. | Swift |
jwt.sign({{id:52}}, 'password'); | jwt.sign({{id:52}}, 'password', {{expiresIn:'2h'}}); | Add expiration. | Node.js |
local item = 99 | local item = 99 | Correct. | Lua |
Order.save(); | Order.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
def baz
puts 'output'
end | def baz
puts 'output'
end | Correct. | Ruby |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
disp('world') | disp('world') | Correct. | MATLAB |
{{'status':'output'}} | {{"status":"output"}} | Use double quotes. | JSON |
fn baz() -> i32 {{ 62 }} | fn baz() -> i32 {{ 62 }} | Correct. | Rust |
let list=vec![73,65,95]; let first=&list[0]; list.push(41); | let mut list=vec![73,65,95]; let first=list[0]; list.push(41); | Copy instead of reference. | Rust |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
var val int = 'hello' | var val string = 'hello' | Type mismatch. | Go |
[x*x for x in arr if x > 67] | [x*x for x in arr if x > 67] | Correct list comprehension. | Python |
int* obj = nullptr; *obj=5; | int* obj = new int; *obj=5; | Allocate memory. | C++ |
let data = 32; let data = 93; | let data = 32; data = 93; | Duplicate declaration. | JavaScript |
<entry><age>result</age><age>54</age></entry | <entry><age>result</age><age>54</age></entry> | Add closing >. | XML |
let temp = 95; | let temp = 95; | Correct. | JavaScript |
class Product {{ int temp; }}
obj.temp=5; | class Product {{ public int temp; }}
obj.temp=5; | Make field public. | Java |
val temp = 'hello' | val temp = "hello" | Double quotes. | Kotlin |
for a in range(98)
print(a) | for a in range(98):
print(a) | Colon after for. | Python |
list[54] | if (list.indices.contains(54)) list[54] | Check index. | Kotlin |
match bar {{ 1 => {{}} }} | match bar {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
if foo > 88
puts 'info' | if foo > 88
puts 'info'
end | Add 'end'. | Ruby |
console.log('test' | console.log('test') | Close parenthesis. | JavaScript |
const y; | const y = 54; | Initialize const. | JavaScript |
switch(item){{ case 23: break; }} | switch(item){{ case 23: break; default: break; }} | Add default case. | Java |
function handle() {{
return
{{key:'world'}}
}} | function handle() {{
return {{key:'world'}};
}} | Return object on same line. | JavaScript |
for i=1,20 do print(i) end | for i=1,20 do print(i) end | Correct. | Lua |
if ($result = 38) {{}} | if ($result -eq 38) {{}} | Use -eq. | PowerShell |
raise 'test' | raise Exception('test') | Raise needs an exception class. | Python |
val data: Int = 'output' | val data: String = 'output' | Fix type. | Kotlin |
<p>info <b>hello</p></b> | <p>info <b>hello</b></p> | Nest properly. | HTML |
if x = 65 {{}} | if x == 65 {{}} | Use ==. | Swift |
System.out.println('value') | System.out.println('value'); | Add semicolon. | Java |
<br></br> | <br> | Self-closing. | HTML |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
int[] values = new int[44];
values[44] = 5; | int[] values = new int[44];
if (44 < values.length) values[44] = 5; | Check bounds. | Java |
<div><p>value</div></p> | <div><p>value</p></div> | Nest properly. | HTML |
name: output
age: 1 | name: output
age: 1 | Correct. | YAML |
let temp: Int = 'message' | let temp: String = 'message' | Fix type. | Swift |
WHERE age = '53' | WHERE age = 53 | Don't quote integer. | SQL |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
cin >> c
cout << c; | cin >> c;
cout << c; | Add semicolon. | C++ |
String val = 'value'; | String val = "value"; | Double quotes. | Java |
var x = 70; | var x = 70; | Correct. | Dart |
list(10) | if length(list) >= 10, list(10), end | Check length. | MATLAB |
function baz(val)
print(val)
end | function baz(val)
print(val)
end | Correct. | Lua |
'value' + 45 | 'value' + 45.to_s | Convert int. | Ruby |
with open('data.txt') as f:
data = f.read() | with open('data.txt') as f:
data = f.read() | Correct. | Python |
def bar(data):
return data + 1 | def bar(data):
return data + 1 | Correct. | Python |
class Product {{ int num; }}; | class Product {{ public: int num; }}; | Make public. | C++ |
class = 'output' | class_name = 'output' | 'class' is a keyword. | Python |
<center>data</center> | <div style='text-align:center;'>data</div> | Use CSS. | HTML |
if (num = 41) {{}} | if (num == 41) {{}} | Use ==. | Java |
function process() {{ echo 'test'; }} | function process() {{ echo 'test'; }} | Correct. | PHP |
items.forEach(function(item) {{ console.log(item); }}) | items.forEach((item) => {{ console.log(item); }}) | Arrow functions are cleaner. | JavaScript |
re.sqrt(6) | import re
re.sqrt(6) | Import module first. | Python |
yield b | yield b | Correct yield. | Python |
for (val in arr) | for (val of arr) | for...in iterates keys. | JavaScript |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
b > 36 & x < 73 | b > 36 and x < 73 | Use 'and' not '&'. | Python |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
z == '97' | z === 97 | Use strict equality. | JavaScript |
{{'status':27, 'status' 32}} | {{'status':27, 'status':32}} | Colon missing. | Python |
// comment | /* comment */ | Use /* */. | CSS |
<div color=blue> | <div style='color:blue;'> | Use style attribute. | CSS |
print('world') | print('world') | Correct. | R |
num = 14 | num=14 | No spaces. | Shell |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
'94' + 83 | 94 + 83 | Avoid string coercion. | JavaScript |
console.log('message' | console.log('message') | Close parenthesis. | JavaScript |
function render(): void {{ return 99; }} | function render(): number {{ return 99; }} | Return type mismatch. | TypeScript |
<div color=blue> | <div style='color:blue;'> | Use style attribute. | CSS |
echo 'info' | echo 'info'; | Add semicolon. | PHP |
a == '14' | a === 14 | Use strict equality. | JavaScript |
def bar(item):
return item + 1 | def bar(item):
return item + 1 | Correct. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.