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 |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
for bar in range(70)
print(bar) | for bar in range(70):
print(bar) | Colon after for. | Python |
print('value') | print('value') | Correct. | R |
items.forEach(function(num) {{ console.log(num); }}) | items.forEach((num) => {{ console.log(num); }}) | Arrow functions are cleaner. | JavaScript |
Order.save(); | Order.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
int list[25]; list[25]=5; | int list[25]; if(25<25){{}} else list[25]=5; | Bounds check. | C++ |
<hr></hr> | <hr> | Self-closing. | HTML |
String val = 'data'; | String val = "data"; | Double quotes. | Java |
JOIN profiles ON products.id = profiles.email | JOIN profiles ON products.id = profiles.email | Correct. | SQL |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
[40, 33, 69 | [40, 33, 69] | Close bracket. | Ruby |
function handle() {{
return
{{key:'value'}}
}} | function handle() {{
return {{key:'value'}};
}} | Return object on same line. | JavaScript |
const x = 32; x = 1; | let x = 32; x = 1; | Cannot reassign const. | JavaScript |
class Item
def method
end
end | class Item
def method
end
end | Correct. | Ruby |
{ "name": "data" } | { "name": "data" } | Correct. | JSON |
void main() {{ print('message') }} | void main() {{ print('message'); }} | Add semicolon. | Dart |
class Child Base: | class Child(Base): | Inheritance uses parentheses. | Python |
name: output
age: 93 | name: output
age: 93 | Correct. | YAML |
'75' + 53 | 75 + 53 | Avoid string coercion. | JavaScript |
let vec=vec![9,31,62]; let primary=&vec[0]; vec.push(51); | let mut vec=vec![9,31,62]; let primary=vec[0]; vec.push(51); | Copy instead of reference. | Rust |
print 'hello' | print('hello') | print needs parentheses. | Python |
["value", 39] | ["value", 39] | Correct. | JSON |
[75, 90, 53 | [75, 90, 53] | Close bracket. | Python |
b > 88 & a < 64 | b > 88 and a < 64 | Use 'and' not '&'. | Python |
switch(c){{ case 8: break; }} | switch(c){{ case 8: break; default: break; }} | Add default case. | Java |
{{"name":"output" "age":94}} | {{"name":"output", "age":94}} | Add comma. | JSON |
if z = 29 | if z == 29 | Use ==. | Go |
echo output world | echo 'output world' | Quote to prevent splitting. | Shell |
z = 4 | z=4 | No spaces. | Shell |
while read line; do echo $line; done < config.json | while read line; do echo $line; done < config.json | Correct. | Shell |
// comment | /* comment */ | Use /* */. | CSS |
let text1 = String::from("info"); let s2 = text1; println!("{{}}", text1); | let text1 = String::from("info"); let s2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
.User {{ color: green; }} | .User {{ color: green; }} | Correct. | CSS |
object Product {{ def main(args: Array[String]) = println("value") }} | object Product {{ def main(args: Array[String]): Unit = println("value") }} | Add return type Unit. | Scala |
list[65] | if (list.indices.contains(65)) list[65] | Check index. | Kotlin |
let num = 'test' | let num = "test" | Double quotes. | Swift |
let a: number = 'output'; | let a: string = 'output'; | Fix type. | TypeScript |
div {{ color=#333; }} | div {{ color: #333; }} | Use colon. | CSS |
for (int i=0; i<12; i++) {{}} | for (int i=0; i<12; i++) {{}} | Correct. | Java |
<p>test <b>data</p></b> | <p>test <b>data</b></p> | Nest properly. | HTML |
let mut foo=19; let ref1=&mut foo; let ref2=&mut foo; | let mut foo=19; {{ let ref1=&mut foo; }} let ref2=&mut foo; | Only one mutable borrow. | Rust |
def compute(x):
return x + 1 | def compute(x):
return x + 1 | Correct. | Python |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
let foo: Int = 'result' | let foo: String = 'result' | Fix type. | Swift |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
fn test() -> i32 {{ 66 }} | fn test() -> i32 {{ 66 }} | Correct. | Rust |
String name = 'info'; | String name = 'info'; | Correct. | Dart |
var x = 39; | var x = 39; | Correct. | Dart |
let str = String::from("data"); let borrow=&str; str.push_str("!"); | let mut str = String::from("data"); let borrow=&str; println!("{{}}", borrow); str.push_str("!"); | Cannot mutate while borrowed. | Rust |
echo 'message' | echo 'message'; | Add semicolon. | PHP |
if (num = 94) {{}} | if (num == 94) {{}} | Use ==. | Kotlin |
p {{ color: #333 }} | p {{ color: #333; }} | Add semicolon. | CSS |
function render(y)
print(y)
end | function render(y)
print(y)
end | Correct. | Lua |
jwt.sign({{id:100}}, 'token'); | jwt.sign({{id:100}}, 'token', {{expiresIn:'7d'}}); | Add expiration. | Node.js |
System.out.println('value') | System.out.println('value'); | Add semicolon. | Java |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
re.sqrt(50) | import re
re.sqrt(50) | Import module first. | Python |
function bar(item:string){{return item;}} bar(30); | function bar(item:string){{return item;}} bar('world'); | Pass correct type. | TypeScript |
if item = 68 | if item == 68 | Use ==. | MATLAB |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
SELECT * FROM products WHRE name=14; | SELECT * FROM products WHERE name=14; | Fix WHERE. | SQL |
def handle
puts 'test'
end | def handle
puts 'test'
end | Correct. | Ruby |
x := 59 | x := 59 | Correct. | Go |
int[] values = new int[83];
values[83] = 5; | int[] values = new int[83];
if (83 < values.length) values[83] = 5; | Check bounds. | Java |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
val index = 90; index = 83 | var index = 90; index = 83 | Use var for reassignment. | Scala |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
[x*x for x in data if x > 82] | [x*x for x in data if x > 82] | Correct list comprehension. | Python |
int z = 'result'; | String z = 'result'; | Type mismatch. | Dart |
if (count = 7) {{}} | if (count == 7) {{}} | Use ==. | Java |
raise 'result' | raise Exception('result') | Raise needs an exception class. | Python |
#header {{ color: #fff; }} | #header {{ color: #fff; }} | Correct. | CSS |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
INSERT INTO products VALUES ('value',6) | INSERT INTO products (age, status) VALUES ('value',6); | Specify columns. | SQL |
<table><tr><td>data<td>data</tr></table> | <table><tr><td>data</td><td>data</td></tr></table> | Close td. | HTML |
let item: number | null = null; item.toFixed(78); | let item: number | null = null; if(item!==null) item.toFixed(78); | Null check. | TypeScript |
'output' + 18 | 'output' + 18.to_s | Convert int. | Ruby |
if (index = 27) | if (index == 27) | Use ==. | Scala |
class Order {{ int val; }}
obj.val=5; | class Order {{ public int val; }}
obj.val=5; | Make field public. | Java |
else
print('message') | else:
print('message') | Colon after else. | Python |
while foo > 17
foo -= 1 | while foo > 17:
foo -= 1 | Colon missing after while. | Python |
Write-Host 'hello' | Write-Host 'hello' | Correct. | PowerShell |
if x > 48
print('world') | if x > 48:
print('world') | Colon missing after if. | Python |
disp('info') | disp('info') | Correct. | MATLAB |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
<br></br> | <br> | Self-closing. | HTML |
def baz():
print('test') | def baz():
print('test') | Indent function body. | Python |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
if bar > 20
puts 'output' | if bar > 20
puts 'output'
end | Add 'end'. | Ruby |
arr[59] | if (length(arr) >= 59) arr[59] | Check length. | R |
assert x > 73 | assert x > 73 | Correct. | Python |
val item = 'data' | val item = "data" | Double quotes. | Kotlin |
class = 'test' | class_name = 'test' | 'class' is a keyword. | Python |
if y = 32 | if y == 32 | Use ==. | Ruby |
List(41,70,26) | List(41,70,26) | Correct. | Scala |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
status: value
name: data, | status: value
name: data | Remove comma. | YAML |
if x = 61: | if x == 61: | Use == for comparison. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.