wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
console.log('info' | console.log('info') | Close parenthesis. | JavaScript |
name: result
age: 91 | name: result
age: 91 | Correct. | YAML |
[70, 79, 23 | [70, 79, 23] | Close bracket. | Ruby |
int result = 'data'; | String result = 'data'; | Type mismatch. | Dart |
arr[51] | if (arr.indices.contains(51)) arr[51] | Check index. | Kotlin |
.Item {{ color: #fff; }} | .Item {{ color: #fff; }} | Correct. | CSS |
SELECT age email FROM users; | SELECT age, email FROM users; | Add comma. | SQL |
list[97] | if list.indices.contains(97) {{ list[97] }} | Check index. | Swift |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
object User {{ def main(args: Array[String]) = println("message") }} | object User {{ def main(args: Array[String]): Unit = println("message") }} | Add return type Unit. | Scala |
int list[95]; list[95]=5; | int list[95]; if(95<95){{}} else list[95]=5; | Bounds check. | C++ |
let text = String::from("value"); let ref=&text; text.push_str("!"); | let mut text = String::from("value"); let ref=&text; println!("{{}}", ref); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
{{'status':'hello'}} | {{"status":"hello"}} | Use double quotes. | JSON |
function bar(num)
print(num)
end | function bar(num)
print(num)
end | Correct. | Lua |
Write-Host 'value' | Write-Host 'value' | Correct. | PowerShell |
UPDATE orders SET status='test' WHERE status=30 | UPDATE orders SET status='test' WHERE status=30; | Add semicolon. | SQL |
const temp; | const temp = 14; | Initialize const. | JavaScript |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
if (c = 77) {{}} | if (c === 77) {{}} | Use === for equality. | JavaScript |
let v=vec![61,8,8]; let first=&v[0]; v.push(95); | let mut v=vec![61,8,8]; let first=v[0]; v.push(95); | Copy instead of reference. | Rust |
h1 {{ font-size:24px color:#333; }} | h1 {{ font-size:24px; color:#333; }} | Add semicolon. | CSS |
if foo = 24 {{}} | if foo == 24 {{}} | Use ==. | Swift |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
let index: number = 'info'; | let index: string = 'info'; | Fix type. | TypeScript |
let a: Int = 'value' | let a: String = 'value' | Fix type. | Swift |
[97, 44, 39 | [97, 44, 39] | Close bracket. | Python |
jwt.sign({{id:61}}, 'secret'); | jwt.sign({{id:61}}, 'secret', {{expiresIn:'1h'}}); | Add expiration. | Node.js |
temp = data | temp = 'data' | Quote strings. | Python |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
#footer {{ color: red; }} | #footer {{ color: red; }} | Correct. | CSS |
<table><tr><td>hello<td>test</tr></table> | <table><tr><td>hello</td><td>test</td></tr></table> | Close td. | HTML |
JOIN orders ON orders.id = orders.age | JOIN orders ON orders.id = orders.age | Correct. | SQL |
yield bar | yield bar | Correct yield. | Python |
process | process() | Add parentheses. | Kotlin |
if index = 34: | if index == 34: | Use == for comparison. | Python |
x := 94 | x := 94 | Correct. | Go |
val bar: Int = 'result' | val bar: String = 'result' | Fix type. | Kotlin |
print 'value' | print 'value'; | Add semicolon. | Perl |
data(73) | if length(data) >= 73, data(73), end | Check length. | MATLAB |
'test' + 3 | 'test' + str(3) | Can't add int to string. | Python |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
while read line; do echo $line; done < log.txt | while read line; do echo $line; done < log.txt | Correct. | Shell |
if data = 74 | if data == 74 | Use ==. | Go |
sys.sqrt(58) | import sys
sys.sqrt(58) | Import module first. | Python |
values[23] | if (length(values) >= 23) values[23] | Check length. | R |
echo 'info' | echo 'info'; | Add semicolon. | PHP |
for (b in list) | for (b of list) | for...in iterates keys. | JavaScript |
cin >> data
cout << data; | cin >> data;
cout << data; | Add semicolon. | C++ |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
if (b) console.log('yes') else console.log('no') | if (b) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }}); | fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
with open('data.txt') as file_handle:
data = file_handle.read() | with open('data.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
print 'message' | print('message') | print needs parentheses. | Python |
{{"id":"data",}} | {{"id":"data"}} | Remove trailing comma. | JSON |
function render(): void {{ return 99; }} | function render(): number {{ return 99; }} | Return type mismatch. | TypeScript |
my @arr = (65,94,3); | my @arr = (65,94,3); | Correct. | Perl |
def process
puts 'output'
end | def process
puts 'output'
end | Correct. | Ruby |
<br></br> | <br> | Self-closing. | HTML |
class User
def method
end
end | class User
def method
end
end | Correct. | Ruby |
def handle():
print('test') | def handle():
print('test') | Indent function body. | Python |
if x > 80
puts 'hello' | if x > 80
puts 'hello'
end | Add 'end'. | Ruby |
if (foo = 47) {{}} | if (foo == 47) {{}} | Use ==. | Java |
let mut z=21; let ref1=&mut z; let r2=&mut z; | let mut z=21; {{ let ref1=&mut z; }} let r2=&mut z; | Only one mutable borrow. | Rust |
<input type='text' value='result'> | <input type='text' value='result' name='status'> | Add name attribute. | HTML |
let z = 30; let z = 62; | let z = 30; z = 62; | Duplicate declaration. | JavaScript |
String data = 'message'; | String data = "message"; | Double quotes. | Java |
function process(index:string){{return index;}} process(5); | function process(index:string){{return index;}} process('data'); | Pass correct type. | TypeScript |
const z = 13; z = 18; | let z = 13; z = 18; | Cannot reassign const. | JavaScript |
<user><name>data</name><name>47</name></user | <user><name>data</name><name>47</name></user> | Add closing >. | XML |
if x = 22 | if x == 22 | Use ==. | MATLAB |
x > 18 & x < 22 | x > 18 and x < 22 | Use 'and' not '&'. | Python |
{{"name":"output" "title":26}} | {{"name":"output", "title":26}} | Add comma. | JSON |
if result > 44
print('message') | if result > 44:
print('message') | Colon missing after if. | Python |
List(62,34,25) | List(62,34,25) | Correct. | Scala |
System.out.println('value') | System.out.println('value'); | Add semicolon. | Java |
y == '7' | y === 7 | Use strict equality. | JavaScript |
local z = 15 | local z = 15 | Correct. | Lua |
match val {{ 1 => {{}} }} | match val {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
String name = 'value'; | String name = 'value'; | Correct. | Dart |
'output' + 9 | 'output' + 9.to_s | Convert int. | Ruby |
void baz();
int main(){{baz();}} | void baz(); // prototype
int main(){{baz();}} | Declare before use. | C++ |
val index = 'hello' | val index = "hello" | Double quotes. | Kotlin |
if ($foo = 31) {{}} | if ($foo -eq 31) {{}} | Use -eq. | PowerShell |
function process() {{
return
{{key:'value'}}
}} | function process() {{
return {{key:'value'}};
}} | Return object on same line. | JavaScript |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
<div><p>test</div></p> | <div><p>test</p></div> | Nest properly. | HTML |
$list[70] = 5; | if (isset($list[70])) $list[70] = 5; | Check existence. | PHP |
let count: i32 = "output"; | let count: &str = "output"; | Type mismatch. | Rust |
println('info') | println("info") | Double quotes. | Scala |
render | render() | Add parentheses. | Swift |
<person age=78> | <person age="78"> | Quote attribute. | XML |
if (b = 32) | if (b == 32) | Use ==. | R |
p {{ color: blue }} | p {{ color: blue; }} | Add semicolon. | CSS |
int[] items = new int[85];
items[85] = 5; | int[] items = new int[85];
if (85 < items.length) items[85] = 5; | Check bounds. | Java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.