From 6da2e71327f42c14caec2c0dbe522722a71108f5 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Thu, 29 Feb 2024 12:48:35 +0100 Subject: [PATCH] feat: add example of how to use python helpers (#53908) --- .../meta.json | 6 ++- .../65df3afd233057f6a620a860.md | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 curriculum/challenges/english/20-upcoming-python/learn-python-by-building-a-blackjack-game/65df3afd233057f6a620a860.md diff --git a/curriculum/challenges/_meta/learn-python-by-building-a-blackjack-game/meta.json b/curriculum/challenges/_meta/learn-python-by-building-a-blackjack-game/meta.json index ac73a8ca48f..7fc9784abdb 100644 --- a/curriculum/challenges/_meta/learn-python-by-building-a-blackjack-game/meta.json +++ b/curriculum/challenges/_meta/learn-python-by-building-a-blackjack-game/meta.json @@ -27,6 +27,10 @@ { "id": "64b171849f925b0773aa434c", "title": "Step 4" + }, + { + "id": "65df3afd233057f6a620a860", + "title": "Step 5" } ] -} +} \ No newline at end of file diff --git a/curriculum/challenges/english/20-upcoming-python/learn-python-by-building-a-blackjack-game/65df3afd233057f6a620a860.md b/curriculum/challenges/english/20-upcoming-python/learn-python-by-building-a-blackjack-game/65df3afd233057f6a620a860.md new file mode 100644 index 00000000000..0511581ef62 --- /dev/null +++ b/curriculum/challenges/english/20-upcoming-python/learn-python-by-building-a-blackjack-game/65df3afd233057f6a620a860.md @@ -0,0 +1,53 @@ +--- +id: 65df3afd233057f6a620a860 +title: Step 5 +challengeType: 20 +dashedName: step-5 +--- + +# --description-- + +This shows how the helper functions can be used to analyze a learner's class definitions + +# --instructions-- + +We can just find the class definition inside Python, return it to the JavaScript, and then check if it contains the string "pass". + +If we need something more reliable, we can expand the helpers to check for pass statements specifically. This would be useful if say, we wanted to write classes containing, say, passengers. + +# --hints-- + +`TreeNode` should not contain any `pass` statements. + +```js +({ test: () => { + const pyClassStr = runPython(`str(_Node(_code).find_class("TreeNode"))`); + assert.notInclude(pyClassStr, "pass") +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +--fcc-editable-region-- +class TreeNode: + pass + +class Trap: + pass +--fcc-editable-region-- +``` + +# --solutions-- + +```py +class TreeNode: + def __init__(self, thing): + self.thing = thing + +class Trap: + pass + +```