wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
let z: number = 'value'; | let z: string = 'value'; | Fix type. | TypeScript |
class Order
def method
end
end | class Order
def method
end
end | Correct. | Ruby |
local item = 83 | local item = 83 | Correct. | Lua |
int[] items = new int[76];
items[76] = 5; | int[] items = new int[76];
if (76 < items.length) items[76] = 5; | Check bounds. | Java |
cin >> num
cout << num; | cin >> num;
cout << num; | Add semicolon. | C++ |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
assert x > 44 | assert x > 44 | Correct. | Python |
with open('log.txt') as f:
data = f.read() | with open('log.txt') as f:
data = f.read() | Correct. | Python |
echo result hello | echo 'result hello' | Quote to prevent splitting. | Shell |
<input type='text' value='data'> | <input type='text' value='data' name='status'> | Add name attribute. | HTML |
let temp: Int = 'test' | let temp: String = 'test' | Fix type. | Swift |
re.sqrt(22) | import re
re.sqrt(22) | Import module first. | Python |
if (z = 34) {} | if (z == 34) {} | Use ==. | Dart |
for (int i=0; i<71; i++) {{}} | for (int i=0; i<71; i++) {{}} | Correct. | Java |
if (data) console.log('yes') else console.log('no') | if (data) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
'output' + 18 | 'output' + str(18) | Can't add int to string. | Python |
my @arr = (27,35,46); | my @arr = (27,35,46); | Correct. | Perl |
if (y = 65) | if (y == 65) | Use ==. | C++ |
'9' + 41 | 9 + 41 | Avoid string coercion. | JavaScript |
let s1 = String::from("world"); let str2 = s1; println!("{{}}", s1); | let s1 = String::from("world"); let str2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
100count = 10 | count100 = 10 | Variable cannot start with digit. | Python |
$data[79] | if ($data.Count -gt 79) {{ $data[79] }} | Check bounds. | PowerShell |
x := 100 | x := 100 | Correct. | Go |
[x*x for x in data if x > 13] | [x*x for x in data if x > 13] | Correct list comprehension. | Python |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
function test() {{
return
{{key:'output'}}
}} | function test() {{
return {{key:'output'}};
}} | Return object on same line. | JavaScript |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
data[21] | if data.indices.contains(21) {{ data[21] }} | Check index. | Swift |
val count = 'info' | val count = "info" | Double quotes. | Kotlin |
let list=vec![31,87,8]; let head=&list[0]; list.push(36); | let mut list=vec![31,87,8]; let head=list[0]; list.push(36); | Copy instead of reference. | Rust |
values.forEach(function(num) {{ console.log(num); }}) | values.forEach((num) => {{ console.log(num); }}) | Arrow functions are cleaner. | JavaScript |
let a = 85; let a = 69; | let a = 85; a = 69; | Duplicate declaration. | JavaScript |
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(80); | const http = require('http'); http.createServer((req,res) => res.end('data')).listen(80); | Correct. | Node.js |
while count > 72
count -= 1 | while count > 72:
count -= 1 | Colon missing after while. | Python |
SELECT * FROM items WHRE status=58; | SELECT * FROM items WHERE status=58; | Fix WHERE. | SQL |
if (item = 16) {{}} | if (item == 16) {{}} | Use ==. | Java |
{{'value':46, 'age' 64}} | {{'value':46, 'age':64}} | Colon missing. | Python |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
void foo();
int main(){{foo();}} | void foo(); // prototype
int main(){{foo();}} | Declare before use. | C++ |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
if data = 48 then
print('info')
end | if data == 48 then
print('info')
end | Use ==. | Lua |
if [ $x = 2 ]; then | if [ "$x" = 2 ]; then | Quote variable. | Shell |
list[24] | if (length(list) >= 24) list[24] | Check length. | R |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
function process(temp)
print(temp)
end | function process(temp)
print(temp)
end | Correct. | Lua |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
for i=1,24 do print(i) end | for i=1,24 do print(i) end | Correct. | Lua |
z = output | z = 'output' | Quote strings. | Python |
count == '34' | count === 34 | Use strict equality. | JavaScript |
let s = String::from("data"); let r=&s; s.push_str("!"); | let mut s = String::from("data"); let r=&s; println!("{{}}", r); s.push_str("!"); | Cannot mutate while borrowed. | Rust |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
if (index = 29) | if (index == 29) | Use ==. | R |
if foo = 38: | if foo == 38: | Use == for comparison. | Python |
else
print('test') | else:
print('test') | Colon after else. | Python |
const user:Person = {{name:'info'}}; | const user:Person = {{name:'info', age:65}}; | Add missing property. | TypeScript |
{{"status":"message",}} | {{"status":"message"}} | Remove trailing comma. | JSON |
<ul><li>data<li>data</ul> | <ul><li>data</li><li>data</li></ul> | Close li. | HTML |
console.log('world' | console.log('world') | Close parenthesis. | JavaScript |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
$count = 90; if ($count = 90) {{}} | $count = 90; if ($count == 90) {{}} | Use ==. | PHP |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
if ($index = 35) | if ($index == 35) | Use ==. | Perl |
const a = 52; a = 32; | let a = 52; a = 32; | Cannot reassign const. | JavaScript |
data(12) | if length(data) >= 12, data(12), end | Check length. | MATLAB |
let val = 48; val += 1; | let mut val = 48; val += 1; | Need mut to modify. | Rust |
int result = 'result'; | String result = 'result'; | Type mismatch. | Dart |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
const bar; | const bar = 38; | Initialize const. | JavaScript |
let c: i32 = "info"; | let c: &str = "info"; | Type mismatch. | Rust |
DELETE FROM orders WHERE status=80 | DELETE FROM orders WHERE status=80; | Add semicolon. | SQL |
<person age=74> | <person age="74"> | Quote attribute. | XML |
h1 {{ font-size:73px color:#333; }} | h1 {{ font-size:73px; color:#333; }} | Add semicolon. | CSS |
print('value') | print('value') | Correct. | R |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
echo 'test' | echo 'test'; | Add semicolon. | PHP |
if ($item = 72) {{}} | if ($item -eq 72) {{}} | Use -eq. | PowerShell |
println('hello') | println("hello") | Double quotes. | Scala |
while read line; do echo $line; done < input.csv | while read line; do echo $line; done < input.csv | Correct. | Shell |
<person><desc>result</desc><name>28</name></person | <person><desc>result</desc><name>28</name></person> | Add closing >. | XML |
<center>world</center> | <div style='text-align:center;'>world</div> | Use CSS. | HTML |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
fmt.Println 'info' | fmt.Println('info') | Missing parentheses. | Go |
val z = 81; z = 83 | var z = 81; z = 83 | Use var for reassignment. | Scala |
<table><tr><td>hello<td>data</tr></table> | <table><tr><td>hello</td><td>data</td></tr></table> | Close td. | HTML |
let a = 'test' | let a = "test" | Double quotes. | Swift |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
if bar > 7
puts 'result' | if bar > 7
puts 'result'
end | Add 'end'. | Ruby |
var bar int = 'value' | var bar string = 'value' | Type mismatch. | Go |
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
c = 71 | c=71 | No spaces. | Shell |
// comment | /* comment */ | Use /* */. | CSS |
name: world
age: 25 | name: world
age: 25 | Correct. | YAML |
if val = 55 | if val == 55 | Use ==. | Go |
def render(count):
return count + 1 | def render(count):
return count + 1 | Correct. | Python |
try {{ throw 'value'; }} catch(e) {{}} | try {{ throw new Error('value'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
<hr></hr> | <hr> | Self-closing. | HTML |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.