fix: Feat/add workshop python functions#68279
Conversation
|
Hi there, Thanks for opening this pull request. The automated checks found some issues: Linked Issue: We kindly ask that contributors open an issue before submitting a PR so the change can be discussed and approved before work begins. This helps avoid situations where significant effort goes into something we ultimately cannot merge. Please open an issue first and allow it to be triaged. Once the issue is open for contribution, you are welcome to update this pull request to reflect the issue consensus. Until then, we will not be able to review your pull request. Join us in our chat room or our forum if you have any questions or need help with contributing. |
majestic-owl448
left a comment
There was a problem hiding this comment.
Please link the issue
also please make sure you are using the AST helpers appropriately, check the documentation for each one again please
|
|
||
| # --description-- | ||
|
|
||
| Welcome to the Python Functions and Scope workshop! We are going to learn about how functions work using a kitchen theme. |
There was a problem hiding this comment.
please don't use second person, workshops should use "you", not "we" or "us"
| @@ -0,0 +1,28 @@ | |||
| { | |||
| "isUpcomingChange": true, | |||
There was a problem hiding this comment.
| "isUpcomingChange": true, | |
| "isUpcomingChange": false, |
| "workshop-report-card-printer", | ||
| "lecture-introduction-to-python-strings", | ||
| "workshop-employee-profile-generator", | ||
| "workshop-kitchen-inventory-tracker", |
There was a problem hiding this comment.
please move below lecture-understanding-functions-and-scope
|
|
||
| ```js | ||
| ({ | ||
| test: () => assert(runPython(`_Node(_code).has_call("take_inventory")`)) |
There was a problem hiding this comment.
has_call wants the function call, not the function name
| ```js | ||
| ({ | ||
| test: () => assert( | ||
| runPython(`_Node(_code).find_assignments("eggs")[-1].is_equivalent("make_fried_egg(eggs)")`) |
There was a problem hiding this comment.
| runPython(`_Node(_code).find_assignments("eggs")[-1].is_equivalent("make_fried_egg(eggs)")`) | |
| runPython(`_Node(_code).find_assignments("eggs")[-1].is_equivalent("eggs = make_fried_egg(eggs)")`) |
| ```js | ||
| ({ | ||
| test: () => assert( | ||
| runPython(`_Node(_code).find_function("make_fried_egg")`) |
There was a problem hiding this comment.
| runPython(`_Node(_code).find_function("make_fried_egg")`) | |
| runPython(`_Node(_code).has_function("make_fried_egg")`) |
| ```js | ||
| ({ | ||
| test: () => assert( | ||
| runPython(`_Node(_code).find_calls("take_inventory()").length === 2`) |
There was a problem hiding this comment.
| runPython(`_Node(_code).find_calls("take_inventory()").length === 2`) | |
| runPython(`_Node(_code).find_calls("take_inventory").length == 2`) |
find_calls wants the function name
also remember that you are running Python inside runPython, Python does not have ===
| test: () => assert(code.match(/print\(\s*f('|")The kitchen has \{total_items\} total items:\1\s*\)/)) | ||
| }) | ||
| ``` | ||
|
|
||
| You should have the print(f'- {eggs} eggs') statement inside your function. | ||
|
|
||
| ```js | ||
| ({ | ||
| test: () => assert(code.match(/print\(\s*f('|")-\s\{eggs\}\seggs\1\s*\)/)) | ||
| }) | ||
| ``` | ||
|
|
||
| You should have the print(f'- {flour} flour') statement inside your function. | ||
|
|
||
| ```js | ||
| ({ | ||
| test: () => assert(code.match(/print\(\s*f('|")-\s\{flour\}\sflour\1\s*\)/)) | ||
| }) | ||
| ``` | ||
|
|
||
| You should have the print(f'- {sugar} sugar') statement inside your function. | ||
|
|
||
| ```js | ||
| ({ | ||
| test: () => assert(code.match(/print\(\s*f('|")-\s\{sugar\}\ssugar\1\s*\)/)) |
There was a problem hiding this comment.
if you are not using runPython, remove the test structure here, but it's preferable you test with the AST helpers even this
… clarity and consistency
| ```js | ||
| ({ | ||
| test: () => assert( | ||
| runPython(`_Node(_code).find_function("take_inventory")`) |
There was a problem hiding this comment.
| runPython(`_Node(_code).find_function("take_inventory")`) | |
| runPython(`_Node(_code).has_function("take_inventory")`) |
the has_ method returns a boolean, please use them in these cases
| ({ | ||
| test: () => assert( | ||
| runPython(` | ||
| _Node(_code).find_function("take_inventory").find_assignments("total_items")[0].is_equivalent("eggs + flour + sugar") |
There was a problem hiding this comment.
| _Node(_code).find_function("take_inventory").find_assignments("total_items")[0].is_equivalent("eggs + flour + sugar") | |
| variable = _Node(_code).find_function("take_inventory").find_variable("total_items") | |
| variable.is_equivalent("total_items = eggs + flour + sugar") or variable.is_equivalent("total_items = eggs + sugar + flour") or ... |
please make sure all 6 permutations are allowed
Checklist:
mainbranch of freeCodeCamp.Closes #64627