Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0a14bac

Browse files
committed
Moved used_x_to_multiply into check() because syntax errors cause early return before checking message steps
1 parentbee2659 commit0a14bac

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

‎backend/main/chapters/c07_nested_loops.py‎

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ class times_table_exercise(ExerciseStep):
124124

125125
parsons_solution=True
126126

127+
defcheck(self):
128+
try:
129+
returnsuper().check()
130+
exceptSyntaxError:
131+
lines=self.result.splitlines()
132+
if (
133+
len(lines)>=3
134+
andlines[2].strip()=="SyntaxError: invalid syntax"
135+
andlines[1].strip()=="^"
136+
andlines[0][lines[1].index("^")]=="x"
137+
):
138+
returndict(message="To multiply numbers, use `*`")
139+
127140
defsolution(self):
128141
forleftinrange(12):
129142
left+=1
@@ -177,29 +190,6 @@ def program(self):
177190
defcheck(self):
178191
return"TypeError: unsupported operand type(s) for +: "inself.result
179192

180-
classused_x_to_multiply(MessageStep):
181-
"""To multiply numbers, use `*`"""
182-
183-
program="2 x 3"
184-
185-
defcheck(self):
186-
"""
187-
Check for a traceback like:
188-
2 x 3
189-
^
190-
SyntaxError: invalid syntax
191-
192-
It might be better to try replacing x with * and see if
193-
it becomes valid syntax
194-
"""
195-
lines=self.result.strip().splitlines()
196-
return (
197-
len(lines)>=3and
198-
lines[-1]=="SyntaxError: invalid syntax"and
199-
lines[-2].strip()=="^"and
200-
lines[-3][lines[-2].index("^")]=="x"
201-
)
202-
203193
tests= {
204194
():"""\
205195
1 x 1 = 1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp