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

Commitbe3b42b

Browse files
committed
More robust check in more_calculation step
1 parentc734221 commitbe3b42b

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

‎backend/main/chapters/c01_the_shell.py‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# flake8: NOQA E501
2-
frommain.textimportMessageStep,Page,Step,VerbatimStep
2+
importast
3+
fromtextwrapimportdedent
4+
5+
frommain.textimportMessageStep,Page,Step,VerbatimStep,search_ast
36

47

58
classIntroducingTheShell(Page):
@@ -37,20 +40,20 @@ class more_calculation(Step):
3740

3841
program="5 - 6"
3942

40-
classx_to_multiple(MessageStep):
41-
"""
43+
defcheck(self):
44+
try:
45+
returnsearch_ast(self.stmt, (ast.Mult,ast.Div,ast.Sub))
46+
exceptSyntaxError:
47+
if"x"inself.input:
48+
returndict(
49+
message=dedent(
50+
"""
4251
I see an 'x'. If you're trying to multiply, use an asterisk, e.g:
4352
4453
3 * 4
4554
"""
46-
47-
program="3 x 4"
48-
49-
defcheck(self):
50-
return"x"inself.input
51-
52-
defcheck(self):
53-
returnself.input_matches(r"\d[-*/]\d")
55+
)
56+
)
5457

5558
final_text="""
5659
Excellent! Keep experimenting. When you're ready, click 'Next' to continue.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp