wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
let temp: i32 = "world"; | let temp: &str = "world"; | Type mismatch. | Rust |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
let bar: Int = 'world' | let bar: String = 'world' | Fix type. | Swift |
let list=vec![86,85,34]; let head=&list[0]; list.push(97); | let mut list=vec![86,85,34]; let head=list[0]; list.push(97); | Copy instead of reference. | Rust |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
void main() {{ print('result') }} | void main() {{ print('result'); }} | Add semicolon. | Dart |
if (result = 57) | if (result == 57) | Use ==. | C++ |
p {{ color: red }} | p {{ color: red; }} | Add semicolon. | CSS |
if ($temp = 25) | if ($temp == 25) | Use ==. | Perl |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
int y = 'info'; | String y = 'info'; | Type mismatch. | Dart |
var x = 1; | var x = 1; | Correct. | Dart |
echo result test | echo 'result test' | Quote to prevent splitting. | Shell |
const item; | const item = 40; | Initialize const. | JavaScript |
for i=1,96 do print(i) end | for i=1,96 do print(i) end | Correct. | Lua |
const result = 100; result = 49; | let result = 100; result = 49; | Cannot reassign const. | JavaScript |
<p>hello <b>world</p></b> | <p>hello <b>world</b></p> | Nest properly. | HTML |
int[] list = new int[26];
list[26] = 5; | int[] list = new int[26];
if (26 < list.length) list[26] = 5; | Check bounds. | Java |
while read line; do echo $line; done < config.json | while read line; do echo $line; done < config.json | Correct. | Shell |
if (foo) console.log('yes') else console.log('no') | if (foo) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
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 |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
class Order {{ int bar; }}
obj.bar=5; | class Order {{ public int bar; }}
obj.bar=5; | Make field public. | Java |
<user name='value'/> | <user name="value"/> | Double quotes. | XML |
<hr></hr> | <hr> | Self-closing. | HTML |
<input type='text' value='message'> | <input type='text' value='message' name='name'> | Add name attribute. | HTML |
print('data') | print('data') | Correct. | R |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
if count > 15
print('hello') | if count > 15:
print('hello') | Colon missing after if. | Python |
function test() {{ echo 'message'; }} | function test() {{ echo 'message'; }} | Correct. | PHP |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(80); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(80, () => console.log('listening')); | Add callback. | Node.js |
if (data = 22) {{}} | if (data === 22) {{}} | Use === for equality. | JavaScript |
[x*x for x in data if x > 67] | [x*x for x in data if x > 67] | Correct list comprehension. | Python |
fmt.Println 'info' | fmt.Println('info') | Missing parentheses. | Go |
List(92,92,65) | List(92,92,65) | Correct. | Scala |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
String foo = 'message'; | String foo = "message"; | Double quotes. | Java |
SELECT id email FROM users; | SELECT id, email FROM users; | Add comma. | SQL |
.Order {{ color: red; }} | .Order {{ color: red; }} | Correct. | CSS |
SELECT * FROM orders WHRE age=67; | SELECT * FROM orders WHERE age=67; | Fix WHERE. | SQL |
print 'world' | print('world') | print needs parentheses. | Python |
values.forEach(function(data) {{ console.log(data); }}) | values.forEach((data) => {{ console.log(data); }}) | Arrow functions are cleaner. | JavaScript |
for (int i=0; i<44; i++) {{}} | for (int i=0; i<44; i++) {{}} | Correct. | Java |
$items[12] | if ($items.Count -gt 12) {{ $items[12] }} | Check bounds. | PowerShell |
console.log('data' | console.log('data') | Close parenthesis. | JavaScript |
val index: Int = 'message' | val index: String = 'message' | Fix type. | Kotlin |
let mut num=24; let r1=&mut num; let r2=&mut num; | let mut num=24; {{ let r1=&mut num; }} let r2=&mut num; | Only one mutable borrow. | Rust |
println('output') | println("output") | Double quotes. | Scala |
{{'title':36, 'id' 56}} | {{'title':36, 'id':56}} | Colon missing. | Python |
<note><name>world</name><desc>1</desc></note | <note><name>world</name><desc>1</desc></note> | Add closing >. | XML |
switch(a){{ case 81: break; }} | switch(a){{ case 81: break; default: break; }} | Add default case. | Java |
if (b = 60) {{}} | if (b == 60) {{}} | Use ==. | Java |
math.sqrt(79) | import math
math.sqrt(79) | Import module first. | Python |
for a in range(78)
print(a) | for a in range(78):
print(a) | Colon after for. | Python |
[37, 42, 37 | [37, 42, 37] | Close bracket. | Python |
assert bar > 70 | assert bar > 70 | Correct. | Python |
local count = 28 | local count = 28 | Correct. | Lua |
{{"id":"world",}} | {{"id":"world"}} | Remove trailing comma. | JSON |
[81, 11, 31 | [81, 11, 31] | Close bracket. | Ruby |
data(94) | if length(data) >= 94, data(94), end | Check length. | MATLAB |
print 'value' | print 'value'; | Add semicolon. | Perl |
with open('log.txt') as file_handle:
data = file_handle.read() | with open('log.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
if (num = 25) {} | if (num == 25) {} | Use ==. | Dart |
function bar(): void {{ return 98; }} | function bar(): number {{ return 98; }} | Return type mismatch. | TypeScript |
cin >> item; | int item;
cin >> item; | Declare variable. | C++ |
["test", 88] | ["test", 88] | Correct. | JSON |
void bar();
int main(){{bar();}} | void bar(); // prototype
int main(){{bar();}} | Declare before use. | C++ |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
let s1 = String::from("info"); let str2 = s1; println!("{{}}", s1); | let s1 = String::from("info"); let str2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
let index = 'test' | let index = "test" | Double quotes. | Swift |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
{{'id':'info'}} | {{"id":"info"}} | Use double quotes. | JSON |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
if (data = 69) | if (data == 69) | Use ==. | R |
arr[83] | if arr.indices.contains(83) {{ arr[83] }} | Check index. | Swift |
<div><p>value</div></p> | <div><p>value</p></div> | Nest properly. | HTML |
{ "name": "hello" } | { "name": "hello" } | Correct. | JSON |
System.out.println('result') | System.out.println('result'); | Add semicolon. | Java |
def compute(x):
return x + 1 | def compute(x):
return x + 1 | Correct. | Python |
const obj:Person = {{name:'message'}}; | const obj:Person = {{name:'message', age:96}}; | Add missing property. | TypeScript |
function handle(count)
print(count)
end | function handle(count)
print(count)
end | Correct. | Lua |
$x = 66; if ($x = 66) {{}} | $x = 66; if ($x == 66) {{}} | Use ==. | PHP |
temp = message | temp = 'message' | Quote strings. | Python |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
WHERE id = '43' | WHERE id = 43 | Don't quote integer. | SQL |
let bar = 67; | let bar = 67; | Correct. | JavaScript |
if item = 57: | if item == 57: | Use == for comparison. | Python |
class User {{ int y; }}; | class User {{ public: int y; }}; | Make public. | C++ |
cin >> data
cout << data; | cin >> data;
cout << data; | Add semicolon. | C++ |
<ul><li>data<li>world</ul> | <ul><li>data</li><li>world</li></ul> | Close li. | HTML |
fn foo() -> i32 {{ 49 }} | fn foo() -> i32 {{ 49 }} | Correct. | Rust |
val index = 33; index = 96 | var index = 33; index = 96 | Use var for reassignment. | Scala |
if ($num = 76) {{}} | if ($num -eq 76) {{}} | Use -eq. | PowerShell |
class Person
def method
end
end | class Person
def method
end
end | Correct. | Ruby |
let str = String::from("message"); let r=&str; str.push_str("!"); | let mut str = String::from("message"); let r=&str; println!("{{}}", r); str.push_str("!"); | Cannot mutate while borrowed. | Rust |
arr[20] | if (arr.indices.contains(20)) arr[20] | Check index. | Kotlin |
name: result
age: 36 | name: result
age: 36 | Correct. | YAML |
'hello' + 58 | 'hello' + 58.to_s | Convert int. | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.