mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix : multiple issues with the pass keyword in the python case converter project (#53602)
Co-authored-by: Dario-DC <105294544+Dario-DC@users.noreply.github.com>
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ In this project, you are going to learn about list comprehensions in Python by b
|
||||
|
||||
List comprehensions in Python are a concise way to construct a list without using loops or the `.append()` method. Apart from being briefer, list comprehensions often run faster.
|
||||
|
||||
Start defining a new function named `convert_to_snake_case()` that accepts a string named `pascal_or_camel_cased_string` as input.
|
||||
Start defining a new function named `convert_to_snake_case()` that accepts a string named `pascal_or_camel_cased_string` as input. For now, add a `pass` statement inside the function.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+3
-2
@@ -19,9 +19,10 @@ You should replace `pass` with an empty list named `snake_cased_char_list` withi
|
||||
({
|
||||
test: () => {
|
||||
const transformedCode = code.replace(/\r/g, "");
|
||||
const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case");
|
||||
const commentless_code = __helpers.python.removeComments(transformedCode)
|
||||
const convert_to_snake_case = __helpers.python.getDef("\n" + commentless_code, "convert_to_snake_case");
|
||||
const { function_body } = convert_to_snake_case;
|
||||
|
||||
assert.notMatch(function_body, /\bpass\b/);
|
||||
assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*\]\s*/);
|
||||
}
|
||||
})
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ dashedName: step-3
|
||||
|
||||
Now that you have an empty list in place, you can start iterating through the input string and start converting each character to snake case.
|
||||
|
||||
Use a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char` which is short for character.
|
||||
Use a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char` which is short for character. For now, add a `pass` statement in the loop body.
|
||||
|
||||
# --hints--
|
||||
|
||||
@@ -22,7 +22,7 @@ You should write a new `for` loop with the target variable named `char`. Don't f
|
||||
const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case");
|
||||
const { function_body } = convert_to_snake_case;
|
||||
|
||||
assert.match(function_body, / +for\s+char\s+in\s+pascal_or_camel_cased_string\s*:/);
|
||||
assert.match(function_body, / +for\s+char\s+in\s+pascal_or_camel_cased_string\s*:\s*pass[\s]*$/);
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
+18
-6
@@ -13,16 +13,28 @@ Inside the loop body, use an `if` statement in conjunction with the `.isupper()`
|
||||
|
||||
# --hints--
|
||||
|
||||
You should write a new `if` statement with `char.isupper()` as the condition. Don't forget the colon at the end.
|
||||
You should write a new if statement with char.isupper() as the condition. Remember to add the colon at the end and use the pass keyword to fill the if statement body.
|
||||
|
||||
```js
|
||||
({
|
||||
test: () => {
|
||||
const transformedCode = code.replace(/\r/g, "");
|
||||
const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case");
|
||||
const { function_body } = convert_to_snake_case;
|
||||
test: () => {
|
||||
const commentless_code = __helpers.python.removeComments(code)
|
||||
const transformedCode = commentless_code.replace(/\r/g, "");
|
||||
const {function_body} = __helpers.python.getDef("\n" + commentless_code, "convert_to_snake_case");
|
||||
assert.match(function_body, /\s+if\s+char\.isupper\s*\(\s*\)\s*:\s+pass/);
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
You should replace the `pass` statement in the loop body with the `if` statement.
|
||||
|
||||
```js
|
||||
({
|
||||
test: () => {
|
||||
const commentless_code = __helpers.python.removeComments(code)
|
||||
const {block_body} = __helpers.python.getBlock(commentless_code, /for\s+char\s+in\s+pascal_or_camel_cased_string\s*/);
|
||||
assert.notMatch(block_body, /^\s+pass/);
|
||||
|
||||
assert.match(function_body, / +if\s+char\.isupper\s*\(\s*\)\s*:/);
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
+12
@@ -33,6 +33,18 @@ You should assign the modified character to a variable named `converted_characte
|
||||
})
|
||||
```
|
||||
|
||||
You should not have `pass` in your `if` statement.
|
||||
|
||||
```js
|
||||
({
|
||||
test: () => {
|
||||
const commentless_code = __helpers.python.removeComments(code);
|
||||
const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+char\.isupper\s*\(\s*\)\s*/);
|
||||
assert.notMatch(block_body, /pass/);
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
+15
@@ -25,6 +25,21 @@ You should call `convert_to_snake_case()` inside the `main()` function and pass
|
||||
})
|
||||
```
|
||||
|
||||
You should not have `pass` in your `main` function.
|
||||
|
||||
```js
|
||||
({
|
||||
test: () => {
|
||||
const commentless_code = __helpers.python.removeComments(code);
|
||||
const transformedCode = commentless_code.replace(/\r/g, "");
|
||||
const main = __helpers.python.getDef("\n" + transformedCode, "main");
|
||||
const { function_body } = main;
|
||||
|
||||
assert.notMatch(function_body, /pass/);
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
+3
-1
@@ -7,7 +7,9 @@ dashedName: step-13
|
||||
|
||||
# --description--
|
||||
|
||||
Before running the `main()` function, you need to make sure that the file is running as a script. Add an `if` statement on the same level as the two existing functions and check whether `__name__ == '__main__'` evaluates to `True` or not.
|
||||
Before running the `main()` function, you need to make sure that the file is running as a script. Add an `if` statement on the same level as the two existing functions and check whether `__name__ == '__main__'`.
|
||||
|
||||
Remember to use `pass` to fill the `if` statement body.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+14
-1
@@ -7,7 +7,7 @@ dashedName: step-14
|
||||
|
||||
# --description--
|
||||
|
||||
Replace pass with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution.
|
||||
Replace `pass` with a call to the `main()` function inside the body of the `if` statement. You should see the given camel or pascal cased string converted to snake case upon execution.
|
||||
|
||||
# --hints--
|
||||
|
||||
@@ -22,6 +22,19 @@ You should add a call to `main()` inside the `if` statement.
|
||||
})
|
||||
```
|
||||
|
||||
You should not have `pass` in your `if` statement.
|
||||
|
||||
```js
|
||||
({
|
||||
test: () => {
|
||||
const commentless_code = __helpers.python.removeComments(code);
|
||||
const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+__name__\s+==\s+'__main__'\s*/);
|
||||
|
||||
assert.notMatch(block_body, /pass/);
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
Reference in New Issue
Block a user