fix(curriculum): editable region in pin extractor workshop and typos (#65109)

This commit is contained in:
majestic-owl448
2026-01-22 18:04:56 +01:00
committed by GitHub
parent 16acad2264
commit c10e8bb551
18 changed files with 57 additions and 46 deletions
@@ -46,8 +46,8 @@ You should not have `pass` in your code anymore.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
--fcc-editable-region--
pass
--fcc-editable-region--
```
@@ -61,8 +61,10 @@ You should call the function `pin_extractor` with `poem` as argument.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
--fcc-editable-region--
--fcc-editable-region--
```
@@ -9,7 +9,7 @@ dashedName: step-4
Now that you have added a function call you can see any error created inside the function in the terminal, and you can always use `print` to see the value of things.
There is a digit of the pin hidden in any line, so inside the function use the `split` method to divide the string in a list of lines. Split the lines on the newline character (`\n`), and assign the resulting list to a variable called `lines`.
There is a digit of the pin hidden in every line, so inside the function use the `split` method to divide the string in a list of lines. Split the lines on the newline character (`\n`), and assign the resulting list to a variable called `lines`.
# --hints--
@@ -38,11 +38,12 @@ The variable `lines` should have a value of `poem.split('\n')`.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
--fcc-editable-region--
--fcc-editable-region--
poem = """Stars and the moon
shine in the sky
white and bright
@@ -56,10 +56,12 @@ You should have `print(line)` inside the loop.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
--fcc-editable-region--
--fcc-editable-region--
poem = """Stars and the moon
shine in the sky
@@ -67,6 +69,5 @@ white and bright
until the end of the night"""
pin_extractor(poem)
--fcc-editable-region--
```
@@ -51,12 +51,14 @@ You should have `print(words)`.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
for line in lines:
print(line)
--fcc-editable-region--
--fcc-editable-region--
poem = """Stars and the moon
shine in the sky
@@ -64,6 +66,5 @@ white and bright
until the end of the night"""
pin_extractor(poem)
--fcc-editable-region--
```
@@ -10,12 +10,12 @@ dashedName: step-7
As you learned in a previous lesson, the `enumerate` function allows to keep track of the index while looping over an iterable:
```py
fruits = ['apple', 'plum', 'bananas']
fruits = ['apple', 'plum', 'bananas']
for index, item in enumerate(fruits):
print(index, item)
for index, item in enumerate(fruits):
print(index, item)
# 0 apple
# 0 apple
# 1 plum
# 2 bananas
```
@@ -63,12 +63,13 @@ You should have `print(line_index, line)` inside the loop.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
--fcc-editable-region--
for line in lines:
print(line)
--fcc-editable-region--
words = line.split()
print(words)
@@ -78,6 +79,5 @@ white and bright
until the end of the night"""
pin_extractor(poem)
--fcc-editable-region--
```
@@ -7,7 +7,7 @@ dashedName: step-8
# --description--
In last line of the loop, update the `print` so that it prints the word inside the `words` list at index `line_index`.
In the last line of the loop, update the `print` call so that it prints the word inside the `words` list at index `line_index`.
# --hints--
@@ -26,14 +26,15 @@ You should have `print(words[line_index])` at the end of the loop.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
for line_index, line in enumerate(lines):
print(line_index, line)
words = line.split()
--fcc-editable-region--
print(words)
--fcc-editable-region--
poem = """Stars and the moon
@@ -42,6 +43,5 @@ white and bright
until the end of the night"""
pin_extractor(poem)
--fcc-editable-region--
```
@@ -51,13 +51,14 @@ Inside the `if` statement you should have `secret_code += str(len(words[line_ind
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
for line_index, line in enumerate(lines):
words = line.split()
--fcc-editable-region--
secret_code += str(len(words[line_index]))
--fcc-editable-region--
return secret_code
poem = """Stars and the moon
@@ -66,6 +67,5 @@ white and bright
until the end of the night"""
print(pin_extractor(poem))
--fcc-editable-region--
```
@@ -41,7 +41,6 @@ You should comment out the `print(pin_extractor(poem))` call.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
@@ -58,6 +57,9 @@ shine in the sky
white and
until the end of the night"""
--fcc-editable-region--
print(pin_extractor(poem))
--fcc-editable-region--
@@ -26,14 +26,15 @@ You should have `print(len(words[line_index]))` at the end of the loop.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
for line_index, line in enumerate(lines):
print(line_index, line)
words = line.split()
--fcc-editable-region--
print(words[line_index])
--fcc-editable-region--
poem = """Stars and the moon
@@ -42,6 +43,5 @@ white and bright
until the end of the night"""
pin_extractor(poem)
--fcc-editable-region--
```
@@ -7,7 +7,7 @@ dashedName: step-10
# --description--
The length returned from `len` is an integer, you need to convert it to a string using the `str` function.
The length returned from `len` is an integer, you need to convert it to a string using the `str` function to be able to add it to the `secret_code` string.
Update the `print` call to print the length as a string.
@@ -28,14 +28,15 @@ You should have `print(str(len(words[line_index])))` at the end of the loop.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
for line_index, line in enumerate(lines):
print(line_index, line)
words = line.split()
--fcc-editable-region--
print(len(words[line_index]))
--fcc-editable-region--
poem = """Stars and the moon
@@ -44,6 +45,5 @@ white and bright
until the end of the night"""
pin_extractor(poem)
--fcc-editable-region--
```
@@ -7,11 +7,11 @@ dashedName: step-11
# --description--
Now you can concatenate `str(len(words[line_index]))` to `secret_code`. Remove the `print` call and use augmented assignment `+=` for concatenation.
Now you can concatenate `str(len(words[line_index]))` to `secret_code`. Remove the `print` call and use the augmented assignment `+=` for concatenation.
# --hints--
Inside the loop you should have `secret_code += str(len(words[line_index]))`
Inside the loop you should have `secret_code += str(len(words[line_index]))`.
```js
({
@@ -26,14 +26,15 @@ Inside the loop you should have `secret_code += str(len(words[line_index]))`
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
for line_index, line in enumerate(lines):
print(line_index, line)
words = line.split()
--fcc-editable-region--
print(str(len(words[line_index])))
--fcc-editable-region--
poem = """Stars and the moon
@@ -42,6 +43,5 @@ white and bright
until the end of the night"""
pin_extractor(poem)
--fcc-editable-region--
```
@@ -7,7 +7,7 @@ dashedName: step-12
# --description--
Remove the two `print` calls and add a `return` statement that returns `secret_code` as last line in the function.
Remove the two `print` calls and add a `return` statement that returns `secret_code` on the last line in the function.
# --hints--
@@ -47,15 +47,17 @@ The `pin_extractor` function should return `secret_code` at the end.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
for line_index, line in enumerate(lines):
--fcc-editable-region--
print(line_index, line)
words = line.split()
print(str(len(words[line_index])))
secret_code += str(len(words[line_index]))
--fcc-editable-region--
poem = """Stars and the moon
@@ -64,6 +66,5 @@ white and bright
until the end of the night"""
pin_extractor(poem)
--fcc-editable-region--
```
@@ -32,7 +32,6 @@ def pin_extractor(poem):
for line_index, line in enumerate(lines):
words = line.split()
secret_code += str(len(words[line_index]))
return secret_code
@@ -40,6 +39,7 @@ poem = """Stars and the moon
shine in the sky
white and bright
until the end of the night"""
--fcc-editable-region--
pin_extractor(poem)
--fcc-editable-region--
@@ -45,7 +45,7 @@ The `else` clause should contain `secret_code += '0'`.
})
```
`secret_code('There\nonce\nwas\na\ndragon')` should return `50000`.
`secret_code('There\nonce\nwas\na\ndragon')` should return `50000`.
```js
({
@@ -60,7 +60,6 @@ The `else` clause should contain `secret_code += '0'`.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
@@ -68,6 +67,9 @@ def pin_extractor(poem):
words = line.split()
if len(words) > line_index:
secret_code += str(len(words[line_index]))
--fcc-editable-region--
--fcc-editable-region--
return secret_code
poem = """Stars and the moon
@@ -76,6 +78,5 @@ white and
until the end of the night"""
print(pin_extractor(poem))
--fcc-editable-region--
```
@@ -41,7 +41,7 @@ The loop should have `poem` as loop variable.
})
```
You should move the existing body of the function into the new `for` loop.
You should move the existing body of the function into the new `for` loop.
```js
({
@@ -73,7 +73,7 @@ You should move the existing body of the function into the new `for` loop.
```py
--fcc-editable-region--
def pin_extractor(poem):
secret_code = ''
lines = poem.split('\n')
for line_index, line in enumerate(lines):
@@ -83,7 +83,7 @@ def pin_extractor(poem):
else:
secret_code += '0'
return secret_code
--fcc-editable-region--
poem = """Stars and the moon
shine in the sky
white and
@@ -93,6 +93,5 @@ poem2 = 'The grass is green\nhere and there\nhoping for rain\nbefore it turns ye
poem3 = 'There\nonce\nwas\na\ndragon'
# print(pin_extractor(poem))
--fcc-editable-region--
```
@@ -7,7 +7,9 @@ dashedName: step-18
# --description--
Before the loop, create a new variable `secret_codes` that has a starting value of an empty list. Replace the `return secret_code` line with a line that appends `secret_code` to the `secret_codes` list.
Before the loop, create a new variable `secret_codes` that has a starting value of an empty list.
Then replace the `return secret_code` line with a line that appends `secret_code` to the `secret_codes` list.
# --hints--
@@ -58,9 +60,9 @@ You should not return `secret_code`.
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poems):
--fcc-editable-region--
for poem in poems:
secret_code = ''
lines = poem.split('\n')
@@ -71,7 +73,8 @@ def pin_extractor(poems):
else:
secret_code += '0'
return secret_code
--fcc-editable-region--
poem = """Stars and the moon
shine in the sky
white and
@@ -81,6 +84,5 @@ poem2 = 'The grass is green\nhere and there\nhoping for rain\nbefore it turns ye
poem3 = 'There\nonce\nwas\na\ndragon'
# print(pin_extractor(poem))
--fcc-editable-region--
```
@@ -70,7 +70,6 @@ assert pin_extractor([plum, apple, grape]) == ['2863', '3885', '9227']
## --seed-contents--
```py
--fcc-editable-region--
def pin_extractor(poems):
secret_codes = []
for poem in poems:
@@ -83,6 +82,8 @@ def pin_extractor(poems):
else:
secret_code += '0'
secret_codes.append(secret_code)
--fcc-editable-region--
poem = """Stars and the moon
shine in the sky