Skip to content

Commit dbeb460

Browse files
committed
fix(demo): "NameError: cannot access free variable" example fixed
1 parent 57ece3e commit dbeb460

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

docs/demo-examples.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ export const examples = [
33
title: "NameError - Variable Not Created Yet",
44
runtime: "skulpt",
55
expectedVariantId: "NameError/variants/0",
6-
code: `def show_total():
7-
print(total)
6+
code: `def outer():
7+
def inner():
8+
return total
89
9-
show_total()`,
10+
print(inner())
11+
total = 10
12+
13+
outer()`,
1014
trace: `Traceback (most recent call last):
11-
File "main.py", line 4, in <module>
12-
File "main.py", line 2, in show_total
13-
NameError: free variable 'total' referenced before assignment in enclosing scope`
15+
File "main.py", line 8, in <module>
16+
outer()
17+
File "main.py", line 5, in outer
18+
print(inner())
19+
File "main.py", line 3, in inner
20+
return total
21+
NameError: cannot access free variable 'total' where it is not associated with a value in enclosing scope`
1422
},
1523
{
1624
title: "NameError - Variable Not Defined Here",

0 commit comments

Comments
 (0)