11export const examples = [
22 {
3- title : "NameError - Undefined Variable" ,
3+ title : "NameError - Variable Not Created Yet " ,
44 runtime : "skulpt" ,
5+ expectedVariantId : "NameError/variants/0" ,
6+ code : `def show_total():
7+ print(total)
8+
9+ show_total()` ,
10+ 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`
14+ } ,
15+ {
16+ title : "NameError - Variable Not Defined Here" ,
17+ runtime : "skulpt" ,
18+ expectedVariantId : "NameError/variants/1" ,
519 code : `print("Hello")
620print(kittens)` ,
721 trace : `Traceback (most recent call last):
@@ -11,27 +25,168 @@ NameError: name 'kittens' is not defined`
1125 {
1226 title : "SyntaxError - Missing Colon" ,
1327 runtime : "skulpt" ,
28+ expectedVariantId : "SyntaxError/variants/0" ,
1429 code : `for i in range(3)
1530 print(i)` ,
1631 trace : `Traceback (most recent call last):
1732File "main.py", line 1
1833 for i in range(3)
1934 ^
2035SyntaxError: invalid syntax`
36+ } ,
37+ {
38+ title : "SyntaxError - Comma Instead Of Colon" ,
39+ runtime : "pyodide" ,
40+ expectedVariantId : "SyntaxError/variants/1" ,
41+ code : `if score > 10,
42+ print("Great")` ,
43+ trace : `Traceback (most recent call last):
44+ File "main.py", line 1
45+ if score > 10,
46+ ^
47+ SyntaxError: invalid syntax`
48+ } ,
49+ {
50+ title : "SyntaxError - Too Many Colons" ,
51+ runtime : "pyodide" ,
52+ expectedVariantId : "SyntaxError/variants/2" ,
53+ code : `if score > 10::
54+ print("Great")` ,
55+ trace : `Traceback (most recent call last):
56+ File "main.py", line 1
57+ if score > 10::
58+ ^
59+ SyntaxError: invalid syntax`
60+ } ,
61+ {
62+ title : "SyntaxError - Unterminated String" ,
63+ runtime : "pyodide" ,
64+ expectedVariantId : "SyntaxError/variants/5" ,
65+ code : `print("Hello` ,
66+ trace : `Traceback (most recent call last):
67+ File "main.py", line 1
68+ print("Hello
69+ ^
70+ SyntaxError: unterminated string literal (detected at line 1)`
71+ } ,
72+ {
73+ title : "SyntaxError - Missing Comma" ,
74+ runtime : "pyodide" ,
75+ expectedVariantId : "SyntaxError/variants/6" ,
76+ code : `numbers = [1 2, 3]` ,
77+ trace : `Traceback (most recent call last):
78+ File "main.py", line 1
79+ numbers = [1 2, 3]
80+ ^
81+ SyntaxError: invalid syntax. Perhaps you forgot a comma?`
82+ } ,
83+ {
84+ title : "SyntaxError - Bracket Not Closed" ,
85+ runtime : "pyodide" ,
86+ expectedVariantId : "SyntaxError/variants/3" ,
87+ code : `total = (1 + 2` ,
88+ trace : `Traceback (most recent call last):
89+ File "main.py", line 1
90+ total = (1 + 2
91+ ^
92+ SyntaxError: '(' was never closed`
93+ } ,
94+ {
95+ title : "SyntaxError - Closing Bracket Mismatch" ,
96+ runtime : "pyodide" ,
97+ expectedVariantId : "SyntaxError/variants/4" ,
98+ code : `values = [1, 2, 3)
99+ print(values)` ,
100+ trace : `Traceback (most recent call last):
101+ File "main.py", line 1
102+ values = [1, 2, 3)
103+ ^
104+ SyntaxError: closing parenthesis ')' does not match opening bracket '['`
105+ } ,
106+ {
107+ title : "SyntaxError - Assignment In Condition" ,
108+ runtime : "pyodide" ,
109+ expectedVariantId : "SyntaxError/variants/7" ,
110+ code : `if score = 10:
111+ print("Great")` ,
112+ trace : `Traceback (most recent call last):
113+ File "main.py", line 1
114+ if score = 10:
115+ ^
116+ SyntaxError: cannot assign to name 'score'`
117+ } ,
118+ {
119+ title : "SyntaxError - Incomplete Input" ,
120+ runtime : "pyodide" ,
121+ expectedVariantId : "SyntaxError/variants/8" ,
122+ code : `value =` ,
123+ trace : `Traceback (most recent call last):
124+ File "main.py", line 3
125+ value =
126+ ^
127+ SyntaxError: incomplete input`
128+ } ,
129+ {
130+ title : "SyntaxError - Invalid Operator" ,
131+ runtime : "pyodide" ,
132+ expectedVariantId : "SyntaxError/variants/9" ,
133+ code : `count = 0
134+ count++` ,
135+ trace : `Traceback (most recent call last):
136+ File "main.py", line 2
137+ count++
138+ ^
139+ SyntaxError: invalid syntax`
140+ } ,
141+ {
142+ title : "SyntaxError - Generic Mismatch" ,
143+ runtime : "pyodide" ,
144+ expectedVariantId : "SyntaxError/variants/10" ,
145+ code : `result = 1 +* 2` ,
146+ trace : `Traceback (most recent call last):
147+ File "main.py", line 1
148+ result = 1 +* 2
149+ ^
150+ SyntaxError: invalid syntax`
151+ } ,
152+ {
153+ title : "IndentationError - Unexpected Indent" ,
154+ runtime : "pyodide" ,
155+ expectedVariantId : "IndentationError/variants/0" ,
156+ code : `print("Start")
157+ print("Oops")` ,
158+ trace : `Traceback (most recent call last):
159+ File "main.py", line 2
160+ print("Oops")
161+ ^
162+ IndentationError: unexpected indent`
21163 } ,
22164 {
23165 title : "AttributeError - Using .push() on List" ,
24166 runtime : "pyodide" ,
167+ expectedVariantId : "AttributeError/variants/0" ,
25168 code : `items = []
26169items.push(3)` ,
27170 trace : `Traceback (most recent call last):
28171File "main.py", line 2, in <module>
29172 items.push(3)
30173AttributeError: 'list' object has no attribute 'push'`
174+ } ,
175+ {
176+ title : "AttributeError - Unknown Method" ,
177+ runtime : "pyodide" ,
178+ expectedVariantId : "AttributeError/variants/1" ,
179+ code : `name = "Ada"
180+ name.shrink()` ,
181+ trace : `Traceback (most recent call last):
182+ File "main.py", line 2, in <module>
183+ name.shrink()
184+ AttributeError: 'str' object has no attribute 'shrink'`
31185 } ,
32186 {
33187 title : "TypeError - Adding String and Number" ,
34188 runtime : "pyodide" ,
189+ expectedVariantId : "TypeError/variants/0" ,
35190 code : `age = 10
36191message = "I am " + age + " years old"` ,
37192 trace : `Traceback (most recent call last):
@@ -42,6 +197,7 @@ TypeError: can only concatenate str (not "int") to str`
42197 {
43198 title : "NameError - Variable Used Before Assignment" ,
44199 runtime : "skulpt" ,
200+ expectedVariantId : "UnboundLocalError/variants/0" ,
45201 code : `def calculate():
46202 result = x + 5
47203 x = 10
@@ -57,6 +213,7 @@ UnboundLocalError: local variable 'x' referenced before assignment`
57213 {
58214 title : "IndexError - List Index Out of Range" ,
59215 runtime : "pyodide" ,
216+ expectedVariantId : "IndexError/variants/0" ,
60217 code : `numbers = [1, 2, 3]
61218print(numbers[5])` ,
62219 trace : `Traceback (most recent call last):
@@ -67,6 +224,7 @@ IndexError: list index out of range`
67224 {
68225 title : "KeyError - Dictionary Key Not Found" ,
69226 runtime : "skulpt" ,
227+ expectedVariantId : "KeyError/variants/0" ,
70228 code : `person = {"name": "Alice", "age": 30}
71229print(person["city"])` ,
72230 trace : `Traceback (most recent call last):
@@ -77,11 +235,22 @@ KeyError: 'city'`
77235 {
78236 title : "ZeroDivisionError - Division by Zero" ,
79237 runtime : "pyodide" ,
238+ expectedVariantId : "ZeroDivisionError/variants/0" ,
80239 code : `result = 10 / 0
81240print(result)` ,
82241 trace : `Traceback (most recent call last):
83242File "main.py", line 1, in <module>
84243 result = 10 / 0
85244ZeroDivisionError: division by zero`
245+ } ,
246+ {
247+ title : "Other - ValueError Fallback" ,
248+ runtime : "pyodide" ,
249+ expectedVariantId : "Other/variants/0" ,
250+ code : `int("abc")` ,
251+ trace : `Traceback (most recent call last):
252+ File "main.py", line 1, in <module>
253+ int("abc")
254+ ValueError: invalid literal for int() with base 10: 'abc'`
86255 }
87256] ;
0 commit comments