wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
Write-Host 'result' | Write-Host 'result' | Correct. | PowerShell |
class Product {{ int result; }}
obj.result=5; | class Product {{ public int result; }}
obj.result=5; | Make field public. | Java |
// comment | /* comment */ | Use /* */. | CSS |
let bar: Int = 'world' | let bar: String = 'world' | Fix type. | Swift |
String name = 'data'; | String name = 'data'; | Correct. | Dart |
jwt.sign({{id:25}}, 'token'); | jwt.sign({{id:25}}, 'token', {{expiresIn:'1h'}}); | Add expiration. | Node.js |
let count = 20; | let count = 20; | Correct. | JavaScript |
SELECT age email FROM products; | SELECT age, email FROM products; | Add comma. | SQL |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
while val > 49
val -= 1 | while val > 49:
val -= 1 | Colon missing after while. | Python |
[75, 11, 18 | [75, 11, 18] | Close bracket. | Python |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
let list=vec![56,78,13]; let primary=&list[0]; list.push(52); | let mut list=vec![56,78,13]; let primary=list[0]; list.push(52); | Copy instead of reference. | Rust |
name: info
age: 95 | name: info
age: 95 | Correct. | YAML |
val c = 59; c = 13 | var c = 59; c = 13 | Use var for reassignment. | Scala |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
for i=1,13 do print(i) end | for i=1,13 do print(i) end | Correct. | Lua |
{{"value":"data",}} | {{"value":"data"}} | Remove trailing comma. | JSON |
let s1 = String::from("output"); let str2 = s1; println!("{{}}", s1); | let s1 = String::from("output"); let str2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
if [ $result = 50 ]; then | if [ "$result" = 50 ]; then | Quote variable. | Shell |
for (int i=0; i<15; i++) {{}} | for (int i=0; i<15; i++) {{}} | Correct. | Java |
h1 {{ font-size:52px color:#333; }} | h1 {{ font-size:52px; color:#333; }} | Add semicolon. | CSS |
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }}); | fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
bar == '79' | bar === 79 | Use strict equality. | JavaScript |
function process(): void {{ return 77; }} | function process(): number {{ return 77; }} | Return type mismatch. | TypeScript |
if (item = 67) {{}} | if (item == 67) {{}} | Use ==. | Kotlin |
'result' + 12 | 'result' + 12.to_s | Convert int. | Ruby |
'hello' + 6 | 'hello' + str(6) | Can't add int to string. | Python |
int[] items = new int[54];
items[54] = 5; | int[] items = new int[54];
if (54 < items.length) items[54] = 5; | Check bounds. | Java |
let y: number | null = null; y.toFixed(4); | let y: number | null = null; if(y!==null) y.toFixed(4); | Null check. | TypeScript |
div {{ color=green; }} | div {{ color: green; }} | Use colon. | CSS |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
if (c) console.log('yes') else console.log('no') | if (c) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
fmt.Println 'info' | fmt.Println('info') | Missing parentheses. | Go |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
SELECT * FROM users WHRE age=68; | SELECT * FROM users WHERE age=68; | Fix WHERE. | SQL |
if foo = 62 {{}} | if foo == 62 {{}} | Use ==. | Swift |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(85); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(85, () => console.log('listening')); | Add callback. | Node.js |
if z > 29
print('value') | if z > 29:
print('value') | Colon missing after if. | Python |
assert bar > 68 | assert bar > 68 | Correct. | Python |
function handle(num)
print(num)
end | function handle(num)
print(num)
end | Correct. | Lua |
my @arr = (22,79,1); | my @arr = (22,79,1); | Correct. | Perl |
{{'age':'value'}} | {{"age":"value"}} | Use double quotes. | JSON |
def render
puts 'value'
end | def render
puts 'value'
end | Correct. | Ruby |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
70a = 10 | a70 = 10 | Variable cannot start with digit. | Python |
<person age=51> | <person age="51"> | Quote attribute. | XML |
String data = 'result'; | String data = "result"; | Double quotes. | Java |
'34' + 73 | 34 + 73 | Avoid string coercion. | JavaScript |
list.forEach(function(count) {{ console.log(count); }}) | list.forEach((count) => {{ console.log(count); }}) | Arrow functions are cleaner. | JavaScript |
class Child Entity: | class Child(Entity): | Inheritance uses parentheses. | Python |
SELECT COUNT(*) FROM items | SELECT COUNT(*) FROM items; | Missing semicolon. | SQL |
if (z = 38) | if (z == 38) | Use ==. | R |
switch(z){{ case 54: break; }} | switch(z){{ case 54: break; default: break; }} | Add default case. | Java |
print 'world' | print 'world'; | Add semicolon. | Perl |
function bar(a:string){{return a;}} bar(63); | function bar(a:string){{return a;}} bar('test'); | Pass correct type. | TypeScript |
{{'value':54, 'value' 11}} | {{'value':54, 'value':11}} | Colon missing. | Python |
let foo = 'test' | let foo = "test" | Double quotes. | Swift |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
$items[45] = 5; | if (isset($items[45])) $items[45] = 5; | Check existence. | PHP |
void main() {{ print('data') }} | void main() {{ print('data'); }} | Add semicolon. | Dart |
<note name='result'/> | <note name="result"/> | Double quotes. | XML |
System.out.println('output') | System.out.println('output'); | Add semicolon. | Java |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
<br></br> | <br> | Self-closing. | HTML |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
<img src='output.jpg'> | <img src='output.jpg' alt='desc'> | Add alt text. | HTML |
WHERE name = '59' | WHERE name = 59 | Don't quote integer. | SQL |
var x int | var x int | Correct. | Go |
[x*x for x in data if x > 74] | [x*x for x in data if x > 74] | Correct list comprehension. | Python |
if b = 77 then
print('result')
end | if b == 77 then
print('result')
end | Use ==. | Lua |
data[85] | if data.indices.contains(85) {{ data[85] }} | Check index. | Swift |
if (y = 43) {} | if (y == 43) {} | Use ==. | Dart |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
def test(x):
return x + 1 | def test(x):
return x + 1 | Correct. | Python |
match b {{ 1 => {{}} }} | match b {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
if ($data = 84) | if ($data == 84) | Use ==. | Perl |
var x = 57; | var x = 57; | Correct. | Dart |
num = message | num = 'message' | Quote strings. | Python |
if z = 92: | if z == 92: | Use == for comparison. | Python |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
val data = 'test' | val data = "test" | Double quotes. | Kotlin |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
DELETE FROM products WHERE name=88 | DELETE FROM products WHERE name=88; | Add semicolon. | SQL |
print 'message' | print('message') | print needs parentheses. | Python |
if (a = 77) | if (a == 77) | Use ==. | C++ |
a > 66 & b < 93 | a > 66 and b < 93 | Use 'and' not '&'. | Python |
echo 'output' | echo 'output'; | Add semicolon. | PHP |
var z int = 'info' | var z string = 'info' | Type mismatch. | Go |
class Item
def method
end
end | class Item
def method
end
end | Correct. | Ruby |
let msg = String::from("world"); let ref=&msg; msg.push_str("!"); | let mut msg = String::from("world"); let ref=&msg; println!("{{}}", ref); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
while read line; do echo $line; done < log.txt | while read line; do echo $line; done < log.txt | Correct. | Shell |
local count = 71 | local count = 71 | Correct. | Lua |
try {{ throw 'world'; }} catch(e) {{}} | try {{ throw new Error('world'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.