mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculum): fix editable region in caesar cipher workshop (#65283)
This commit is contained in:
+1
-1
@@ -44,9 +44,9 @@ You should call the `print()` function passing in `shifted_alphabet` as an argum
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shift = 5
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+3
-3
@@ -47,10 +47,10 @@ assert _first or _second
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shift = 5
|
||||
shifted_alphabet = alphabet[shift:]
|
||||
print(shifted_alphabet)
|
||||
--fcc-editable-region--
|
||||
shifted_alphabet = alphabet[shift:]
|
||||
--fcc-editable-region--
|
||||
print(shifted_alphabet)
|
||||
```
|
||||
|
||||
+1
-1
@@ -22,10 +22,10 @@ You should remove `print(shifted_alphabet)` from your code.
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shift = 5
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
--fcc-editable-region--
|
||||
print(shifted_alphabet)
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+1
-1
@@ -38,10 +38,10 @@ You should call `str.maketrans()` passing in `alphabet` and `shifted_alphabet` a
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shift = 5
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+1
-1
@@ -28,11 +28,11 @@ You should assign the string `hello world` to `text`. Remember to enclose the st
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shift = 5
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
translation_table = str.maketrans(alphabet, shifted_alphabet)
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+1
-1
@@ -38,12 +38,12 @@ You should assign `text.translate(translation_table)` to `encrypted_text`.
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shift = 5
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
translation_table = str.maketrans(alphabet, shifted_alphabet)
|
||||
text = 'hello world'
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+1
-1
@@ -22,13 +22,13 @@ You should print `encrypted_text`.
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shift = 5
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
translation_table = str.maketrans(alphabet, shifted_alphabet)
|
||||
text = 'hello world'
|
||||
encrypted_text = text.translate(translation_table)
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+1
@@ -38,6 +38,7 @@ You should move all the code you wrote so far within the `caesar` function body.
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shift = 5
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ def caesar():
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
translation_table = str.maketrans(alphabet, shifted_alphabet)
|
||||
text = 'hello world'
|
||||
--fcc-editable-region--
|
||||
encrypted_text = text.translate(translation_table)
|
||||
print(encrypted_text)
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+1
-1
@@ -34,8 +34,8 @@ def caesar(text, shift):
|
||||
translation_table = str.maketrans(alphabet, shifted_alphabet)
|
||||
encrypted_text = text.translate(translation_table)
|
||||
print(encrypted_text)
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+1
-1
@@ -29,8 +29,8 @@ def caesar(text, shift):
|
||||
encrypted_text = text.translate(translation_table)
|
||||
print(encrypted_text)
|
||||
|
||||
--fcc-editable-region--
|
||||
encrypted_text = caesar('freeCodeCamp', 3)
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+1
-2
@@ -41,16 +41,15 @@ Your `caesar` function should return `text.translate(translation_table)`.
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
def caesar(text, shift):
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
translation_table = str.maketrans(alphabet, shifted_alphabet)
|
||||
--fcc-editable-region--
|
||||
encrypted_text = text.translate(translation_table)
|
||||
print(encrypted_text)
|
||||
--fcc-editable-region--
|
||||
|
||||
encrypted_text = caesar('freeCodeCamp', 3)
|
||||
print(encrypted_text)
|
||||
|
||||
```
|
||||
|
||||
-1
@@ -39,7 +39,6 @@ def caesar(text, shift):
|
||||
--fcc-editable-region--
|
||||
return text.translate(translation_table)
|
||||
|
||||
|
||||
encrypted_text = caesar('freeCodeCamp', 3)
|
||||
print(encrypted_text)
|
||||
```
|
||||
|
||||
+3
-2
@@ -41,16 +41,17 @@ You should return the string `Shift must be an integer value.` from your `if` st
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
def caesar(text, shift):
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())
|
||||
return text.translate(translation_table)
|
||||
|
||||
|
||||
encrypted_text = caesar('freeCodeCamp', 3)
|
||||
print(encrypted_text)
|
||||
```
|
||||
|
||||
+5
-4
@@ -29,17 +29,18 @@ Your `if` statement should use `isinstance(shift, int)` as its condition.
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
def caesar(text, shift):
|
||||
if True:
|
||||
return 'Shift must be an integer value.'
|
||||
|
||||
--fcc-editable-region--
|
||||
if True:
|
||||
--fcc-editable-region--
|
||||
return 'Shift must be an integer value.'
|
||||
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())
|
||||
return text.translate(translation_table)
|
||||
|
||||
|
||||
encrypted_text = caesar('freeCodeCamp', 3)
|
||||
print(encrypted_text)
|
||||
```
|
||||
|
||||
+5
-4
@@ -29,17 +29,18 @@ You should use the `not` operator to negate `isinstance(shift, int)` in your `if
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
def caesar(text, shift):
|
||||
if isinstance(shift, int):
|
||||
return 'Shift must be an integer value.'
|
||||
|
||||
--fcc-editable-region--
|
||||
if isinstance(shift, int):
|
||||
--fcc-editable-region--
|
||||
return 'Shift must be an integer value.'
|
||||
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())
|
||||
return text.translate(translation_table)
|
||||
|
||||
|
||||
encrypted_text = caesar('freeCodeCamp', 3)
|
||||
print(encrypted_text)
|
||||
```
|
||||
|
||||
+4
-3
@@ -32,18 +32,19 @@ Your second `if` statement should return `Shift must be a positive integer.`.
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
def caesar(text, shift):
|
||||
if not isinstance(shift, int):
|
||||
return 'Shift must be an integer value.'
|
||||
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())
|
||||
return text.translate(translation_table)
|
||||
|
||||
|
||||
encrypted_text = caesar('freeCodeCamp', 3)
|
||||
print(encrypted_text)
|
||||
```
|
||||
|
||||
+3
-1
@@ -37,18 +37,20 @@ Your second `if` statement should return `Shift must be an integer between 1 and
|
||||
|
||||
```py
|
||||
def caesar(text, shift):
|
||||
|
||||
if not isinstance(shift, int):
|
||||
return 'Shift must be an integer value.'
|
||||
|
||||
--fcc-editable-region--
|
||||
if shift < 1:
|
||||
return 'Shift must be a positive integer.'
|
||||
--fcc-editable-region--
|
||||
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
|
||||
translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())
|
||||
return text.translate(translation_table)
|
||||
|
||||
|
||||
encrypted_text = caesar('freeCodeCamp', 3)
|
||||
print(encrypted_text)
|
||||
```
|
||||
|
||||
+1
-1
@@ -34,6 +34,7 @@ You should add a third parameter named `encrypt` with a default value of `True`
|
||||
--fcc-editable-region--
|
||||
def caesar(text, shift):
|
||||
--fcc-editable-region--
|
||||
|
||||
if not isinstance(shift, int):
|
||||
return 'Shift must be an integer value.'
|
||||
|
||||
@@ -45,7 +46,6 @@ def caesar(text, shift):
|
||||
translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())
|
||||
return text.translate(translation_table)
|
||||
|
||||
|
||||
encrypted_text = caesar('freeCodeCamp', 3)
|
||||
print(encrypted_text)
|
||||
```
|
||||
|
||||
-1
@@ -43,7 +43,6 @@ def caesar(text, shift, encrypt=True):
|
||||
encrypted_text = text.translate(translation_table)
|
||||
return encrypted_text
|
||||
|
||||
|
||||
encrypted_text = caesar('freeCodeCamp', 3)
|
||||
print(encrypted_text)
|
||||
```
|
||||
|
||||
+2
-1
@@ -45,8 +45,9 @@ def encrypt(text, shift):
|
||||
|
||||
def decrypt(text, shift):
|
||||
return caesar(text, shift, encrypt=False)
|
||||
|
||||
--fcc-editable-region--
|
||||
encrypted_text = caesar('freeCodeCamp', 3)
|
||||
print(encrypted_text)
|
||||
--fcc-editable-region--
|
||||
print(encrypted_text)
|
||||
```
|
||||
|
||||
+1
@@ -67,6 +67,7 @@ def encrypt(text, shift):
|
||||
|
||||
def decrypt(text, shift):
|
||||
return caesar(text, shift, encrypt=False)
|
||||
|
||||
--fcc-editable-region--
|
||||
encrypted_text = encrypt('freeCodeCamp', 3)
|
||||
print(encrypted_text)
|
||||
|
||||
Reference in New Issue
Block a user