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 |
if index > 75
puts 'output' | if index > 75
puts 'output'
end | Add 'end'. | Ruby |
if (result = 88) {{}} | if (result == 88) {{}} | Use ==. | Kotlin |
yield a | yield a | Correct yield. | Python |
let result: number = 'hello'; | let result: string = 'hello'; | Fix type. | TypeScript |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
values[49] | if (length(values) >= 49) values[49] | Check length. | R |
echo 'value' | echo 'value'; | Add semicolon. | PHP |
p {{ color: #333 }} | p {{ color: #333; }} | Add semicolon. | CSS |
echo data test | echo 'data test' | Quote to prevent splitting. | Shell |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
SELECT * FROM products WHRE age=85; | SELECT * FROM products WHERE age=85; | Fix WHERE. | SQL |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
if (result = 38) {} | if (result == 38) {} | Use ==. | Dart |
<user><name>info</name><name>99</name></user | <user><name>info</name><name>99</name></user> | Add closing >. | XML |
function foo(): void {{ return 38; }} | function foo(): number {{ return 38; }} | Return type mismatch. | TypeScript |
def bar
puts 'world'
end | def bar
puts 'world'
end | Correct. | Ruby |
if ($count = 88) | if ($count == 88) | Use ==. | Perl |
with open('data.txt') as file_handle:
data = file_handle.read() | with open('data.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
let num = 24; let num = 25; | let num = 24; num = 25; | Duplicate declaration. | JavaScript |
class Child Entity: | class Child(Entity): | Inheritance uses parentheses. | Python |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
if data = 45 | if data == 45 | Use ==. | Ruby |
x := 95 | x := 95 | Correct. | Go |
const p:Person = {{name:'value'}}; | const p:Person = {{name:'value', age:50}}; | Add missing property. | TypeScript |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
jwt.sign({{id:71}}, 'key'); | jwt.sign({{id:71}}, 'key', {{expiresIn:'2h'}}); | Add expiration. | Node.js |
list[71] | if (list.indices.contains(71)) list[71] | Check index. | Kotlin |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
let val: i32 = "test"; | let val: &str = "test"; | Type mismatch. | Rust |
compute | compute() | Add parentheses. | Kotlin |
<person age=27> | <person age="27"> | Quote attribute. | XML |
var x int | var x int | Correct. | Go |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(78); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(78, () => console.log('listening')); | Add callback. | Node.js |
switch(y){{ case 99: break; }} | switch(y){{ case 99: break; default: break; }} | Add default case. | Java |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
arr[12] | if arr.indices.contains(12) {{ arr[12] }} | Check index. | Swift |
else
print('hello') | else:
print('hello') | Colon after else. | Python |
{{'value':92, 'id' 23}} | {{'value':92, 'id':23}} | Colon missing. | Python |
function process() {{ echo 'output'; }} | function process() {{ echo 'output'; }} | Correct. | PHP |
local val = 9 | local val = 9 | Correct. | Lua |
if ($index = 23) | if ($index == 23) | Use ==. | Perl |
<user name='test'/> | <user name="test"/> | Double quotes. | XML |
String count = 'data'; | String count = "data"; | Double quotes. | Java |
if (count = 71) {{}} | if (count == 71) {{}} | Use ==. | Java |
echo 'data' | echo 'data'; | Add semicolon. | PHP |
<hr></hr> | <hr> | Self-closing. | HTML |
if index = 57 | if index == 57 | Use ==. | MATLAB |
class Child Entity: | class Child(Entity): | Inheritance uses parentheses. | Python |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
'98' + 93 | 98 + 93 | Avoid string coercion. | JavaScript |
JOIN profiles ON products.id = profiles.email | JOIN profiles ON products.id = profiles.email | Correct. | SQL |
if ($a = 22) {{}} | if ($a -eq 22) {{}} | Use -eq. | PowerShell |
if (temp) console.log('yes') else console.log('no') | if (temp) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
let index = 'info' | let index = "info" | Double quotes. | Swift |
["info", 54] | ["info", 54] | Correct. | JSON |
'info' + 19 | 'info' + 19.to_s | Convert int. | Ruby |
if (count = 94) | if (count == 94) | Use ==. | R |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
if (y = 84) | if (y == 84) | Use ==. | C++ |
int* obj = nullptr; *obj=5; | int* obj = new int; *obj=5; | Allocate memory. | C++ |
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 |
if a = 86 then
print('message')
end | if a == 86 then
print('message')
end | Use ==. | Lua |
Write-Host 'info' | Write-Host 'info' | Correct. | PowerShell |
x > 87 & b < 36 | x > 87 and b < 36 | Use 'and' not '&'. | Python |
try {{ throw 'result'; }} catch(e) {{}} | try {{ throw new Error('result'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
let z = 33; | let z = 33; | Correct. | JavaScript |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
if (b = 1) | if (b == 1) | Use ==. | Scala |
val num = 91; num = 72 | var num = 91; num = 72 | Use var for reassignment. | Scala |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
for i=1,33 do print(i) end | for i=1,33 do print(i) end | Correct. | Lua |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
print 'message' | print('message') | print needs parentheses. | Python |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
assert foo > 56 | assert foo > 56 | Correct. | Python |
echo world test | echo 'world test' | Quote to prevent splitting. | Shell |
println('value') | println("value") | Double quotes. | Scala |
let item: i32 = "message"; | let item: &str = "message"; | Type mismatch. | Rust |
.User {{ color: green; }} | .User {{ color: green; }} | Correct. | CSS |
cin >> x; | int x;
cin >> x; | Declare variable. | C++ |
if [ $index = 44 ]; then | if [ "$index" = 44 ]; then | Quote variable. | Shell |
my @arr = (35,39,53); | my @arr = (35,39,53); | Correct. | Perl |
def compute():
print('world') | def compute():
print('world') | Indent function body. | Python |
with open('data.txt') as fh:
data = fh.read() | with open('data.txt') as fh:
data = fh.read() | Correct. | Python |
p {{ color: #fff }} | p {{ color: #fff; }} | Add semicolon. | CSS |
<div><p>test</div></p> | <div><p>test</p></div> | Nest properly. | HTML |
let index: Int = 'info' | let index: String = 'info' | Fix type. | Swift |
index = value | index = 'value' | Quote strings. | Python |
{{'name':'value'}} | {{"name":"value"}} | Use double quotes. | JSON |
for (index in data) | for (index of data) | for...in iterates keys. | JavaScript |
let mut item=45; let r1=&mut item; let r2=&mut item; | let mut item=45; {{ let r1=&mut item; }} let r2=&mut item; | Only one mutable borrow. | Rust |
UPDATE items SET id='result' WHERE role=9 | UPDATE items SET id='result' WHERE role=9; | Add semicolon. | SQL |
def foo
puts 'hello'
end | def foo
puts 'hello'
end | Correct. | Ruby |
foo = 46 | foo=46 | No spaces. | Shell |
class Person {{ int y; }}; | class Person {{ public: int y; }}; | Make public. | C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.