mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-22 21:08:12 +08:00
feat: add example of how to use python helpers (#53908)
This commit is contained in:
parent
fab633088f
commit
6da2e71327
@ -27,6 +27,10 @@
|
||||
{
|
||||
"id": "64b171849f925b0773aa434c",
|
||||
"title": "Step 4"
|
||||
},
|
||||
{
|
||||
"id": "65df3afd233057f6a620a860",
|
||||
"title": "Step 5"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
```
|
||||
Loading…
Reference in New Issue
Block a user