Skip to content

Commit 229635e

Browse files
RitamPal26Ritam PalDario-DC
authored
feat(curriculum): add steps for employee profile generator workshop (freeCodeCamp#64896)
Co-authored-by: Ritam Pal <ritamjunior26@example.com> Co-authored-by: Dario <105294544+Dario-DC@users.noreply.github.com>
1 parent fb6c5d9 commit 229635e

21 files changed

Lines changed: 1027 additions & 0 deletions

client/i18n/locales/english/intro.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3657,6 +3657,12 @@
36573657
"title": "Introduction to Strings",
36583658
"intro": ["In these lessons, you will learn about strings in Python."]
36593659
},
3660+
"workshop-employee-profile-generator": {
3661+
"title": "Build an Employee Profile Generator",
3662+
"intro": [
3663+
"In this workshop, you will practice the fundamentals of string manipulation in Python by building a tool that generates formatted employee badges and analyzes employee codes."
3664+
]
3665+
},
36603666
"lecture-numbers-and-mathematical-operations": {
36613667
"title": "Numbers and Mathematical Operations",
36623668
"intro": [
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
id: 694bf3af05d10fd89dab05cc
3+
title: Step 2
4+
challengeType: 20
5+
dashedName: step-2
6+
---
7+
8+
# --description--
9+
10+
In Python, you can combine strings using the `+` operator. This is called concatenation. Here is an example:
11+
12+
```python
13+
greeting = 'Hello' + 'World'
14+
print(greeting) # Output: HelloWorld
15+
```
16+
17+
Create a variable `full_name` by concatenating `first_name` and `last_name`. Then print `full_name`.
18+
19+
# --hints--
20+
21+
You should have a variable named `full_name`.
22+
23+
```js
24+
({ test: () => assert(runPython(`_Node(_code).has_variable("full_name")`)) })
25+
```
26+
27+
You should assign a string formed by concatenating `first_name` and `last_name` to your `full_name` variable.
28+
29+
```js
30+
({ test: () => assert(runPython(`_Node(_code).find_variable("full_name").is_equivalent("full_name = first_name + last_name")`)) })
31+
```
32+
33+
You should print the `full_name` variable.
34+
35+
```js
36+
({ test: () => assert(runPython(`_Node(_code).has_call("print(full_name)")`)) })
37+
```
38+
39+
# --seed--
40+
41+
## --seed-contents--
42+
43+
```python
44+
first_name = 'John'
45+
last_name = 'Doe'
46+
print(first_name)
47+
print(last_name)
48+
--fcc-editable-region--
49+
50+
--fcc-editable-region--
51+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
id: 694bf6ea530e19a9c48c59f0
3+
title: Step 3
4+
challengeType: 20
5+
dashedName: step-3
6+
---
7+
8+
# --description--
9+
10+
If you concatenate two strings like `'John' + 'Doe'`, the result is `'JohnDoe'` with no space. To fix this, you need to concatenate a string containing a space (`' '`) between them.
11+
12+
13+
Update your `full_name` variable so it concatenates `first_name`, a space, and `last_name`.
14+
15+
# --hints--
16+
17+
You should add a space (`' '`) between `first_name` and `last_name`.
18+
19+
```js
20+
({ test: () => assert(runPython(`_Node(_code).find_variable("full_name").is_equivalent("full_name = first_name + ' ' + last_name")`)) })
21+
```
22+
23+
# --seed--
24+
25+
## --seed-contents--
26+
27+
```python
28+
first_name = 'John'
29+
last_name = 'Doe'
30+
print(first_name)
31+
print(last_name)
32+
--fcc-editable-region--
33+
full_name = first_name + last_name
34+
--fcc-editable-region--
35+
print(full_name)
36+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
id: 694bf6eb530e19a9c48c59f1
3+
title: Step 5
4+
challengeType: 20
5+
dashedName: step-5
6+
---
7+
8+
# --description--
9+
10+
Now, your address seems incomplete. You also want to add the apartment number where the employee lives, so you should modify the variable.
11+
12+
When you want to add content to the end of an existing string variable, you can use the **augmented assignment** operator ,`+=`. This is shorter than writing `var = var + 'new text'`. For example:
13+
14+
```py
15+
greeting = 'Hello'
16+
greeting += ' World'
17+
print(greeting) # Hello World
18+
```
19+
20+
Remember that strings are immutable, therefore this operation does not change the original string. Instead it creates a new string and reassigns it to the variable.
21+
22+
Use the `+=` operator to add the string `, Apartment 4B` to your `address` variable.
23+
24+
# --hints--
25+
26+
You should use the `+=` operator to add the string `, Apartment 4B` to the `address` variable.
27+
28+
```js
29+
({ test: () => assert(runPython(`_Node(_code).find_aug_variable("address").is_equivalent("address += ', Apartment 4B'")`)) })
30+
```
31+
32+
# --seed--
33+
34+
## --seed-contents--
35+
36+
```python
37+
first_name = 'John'
38+
last_name = 'Doe'
39+
print(first_name)
40+
print(last_name)
41+
full_name = first_name + ' ' + last_name
42+
print(full_name)
43+
address = '123 Main Street'
44+
--fcc-editable-region--
45+
46+
--fcc-editable-region--
47+
print(address)
48+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
id: 694bf6eb530e19a9c48c59f2
3+
title: Step 11
4+
challengeType: 20
5+
dashedName: step-11
6+
---
7+
8+
# --description--
9+
10+
Now complete the sentence by concatenating the string ` years old` to the end of `employee_info`. Remember to include a space at the beginning of your string.
11+
12+
Finally, print `employee_info`.
13+
14+
# --hints--
15+
16+
You should concatenate `' years old'` to the end of the `employee_info` variable.
17+
18+
```js
19+
({ test: () => assert(runPython(`_Node(_code).find_variable("employee_info").is_equivalent("employee_info = full_name + ' is ' + str(employee_age) + ' years old'")`)) })
20+
```
21+
22+
You should print `employee_info`.
23+
24+
```js
25+
({ test: () => assert(runPython(`_Node(_code).has_call("print(employee_info)")`)) })
26+
```
27+
28+
# --seed--
29+
30+
## --seed-contents--
31+
32+
```py
33+
first_name = 'John'
34+
last_name = 'Doe'
35+
full_name = first_name + ' ' + last_name
36+
address = '123 Main Street'
37+
address += ', Apartment 4B'
38+
employee_age = 28
39+
--fcc-editable-region--
40+
employee_info = full_name + ' is ' + str(employee_age)
41+
42+
--fcc-editable-region--
43+
```
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
id: 694bf6eb530e19a9c48c59f3
3+
title: Step 12
4+
challengeType: 20
5+
dashedName: step-12
6+
---
7+
8+
# --description--
9+
10+
Now you're going to use the `str()` function one more time. Just like with age, you must convert any numeric variable to a string before concatenating it with other text.
11+
12+
Create a variable named `experience_years` and assign it the integer `5`.
13+
14+
Then, create a variable `experience_info`. Assign it a string formed by concatenating `'Experience: '`, the `experience_years` variable (converted to a string), and `' years'`. Print the result to the terminal.
15+
16+
# --hints--
17+
18+
You should have a variable named `experience_years`.
19+
20+
```js
21+
({ test: () => assert(runPython(`_Node(_code).has_variable("experience_years")`)) })
22+
```
23+
24+
You should assign the integer `5` to your `experience_years` variable.
25+
26+
```js
27+
({ test: () => assert(runPython(`_Node(_code).find_variable("experience_years").is_equivalent("experience_years = 5")`)) })
28+
```
29+
30+
You should have a variable named `experience_info`.
31+
32+
```js
33+
({ test: () => assert(runPython(`_Node(_code).has_variable("experience_info")`)) })
34+
```
35+
36+
You should assign a string formed by concatenating `'Experience: '`, `str(experience_years)`, and `' years'` to your `experience_info` variable.
37+
38+
```js
39+
({ test: () => assert(runPython(`_Node(_code).find_variable("experience_info").is_equivalent("experience_info = 'Experience: ' + str(experience_years) + ' years'")`)) })
40+
```
41+
42+
You should print `experience_info`.
43+
44+
```js
45+
({ test: () => assert(runPython(`_Node(_code).has_call("print(experience_info)")`)) })
46+
```
47+
48+
# --seed--
49+
50+
## --seed-contents--
51+
52+
```python
53+
first_name = 'John'
54+
last_name = 'Doe'
55+
full_name = first_name + ' ' + last_name
56+
address = '123 Main Street'
57+
address += ', Apartment 4B'
58+
employee_age = 28
59+
employee_info = full_name + ' is ' + str(employee_age) + ' years old'
60+
print(employee_info)
61+
--fcc-editable-region--
62+
63+
--fcc-editable-region--
64+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
id: 694bf6eb530e19a9c48c59f4
3+
title: Step 13
4+
challengeType: 20
5+
dashedName: step-13
6+
---
7+
8+
# --description--
9+
10+
Concatenating many strings using `+` and converting numbers using `str()` can get messy and hard to read.
11+
12+
Python 3.6 introduced **f-strings** to solve this. By adding the letter `f` before the opening quote, you can put variables and expressions inside replacement fields represented represented by curly braces `{}`. For example:
13+
14+
```python
15+
name = 'John'
16+
print(f'Hello {name}') # Output: Hello John
17+
```
18+
19+
Create a variable `employee_card` and assign it an f-string that displays `Employee:` followed by a space and the value of the `full_name` variable.
20+
21+
# --hints--
22+
23+
You should have a variable named `employee_card`.
24+
25+
```js
26+
({ test: () => assert(runPython(`_Node(_code).has_variable("employee_card")`)) })
27+
```
28+
29+
Your `employee_card` variable should have the value `f'Employee: {full_name}'`.
30+
31+
```js
32+
({ test: () => assert(runPython(`_Node(_code).find_variable("employee_card").is_equivalent("employee_card = f'Employee: {full_name}'")`)) })
33+
```
34+
35+
# --seed--
36+
37+
## --seed-contents--
38+
39+
```python
40+
first_name = 'John'
41+
last_name = 'Doe'
42+
full_name = first_name + ' ' + last_name
43+
address = '123 Main Street'
44+
address += ', Apartment 4B'
45+
employee_age = 28
46+
employee_info = full_name + ' is ' + str(employee_age) + ' years old'
47+
print(employee_info)
48+
experience_years = 5
49+
experience_info = 'Experience: ' + str(experience_years) + ' years'
50+
print(experience_info)
51+
--fcc-editable-region--
52+
53+
--fcc-editable-region--
54+
```
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
id: 694bf6eb530e19a9c48c59f5
3+
title: Step 16
4+
challengeType: 20
5+
dashedName: step-16
6+
---
7+
8+
# --description--
9+
10+
When working with strings, you'll often need to extract a specific portion of a string. This is called **slicing**.
11+
12+
The syntax is `string[start:stop]`, where:
13+
14+
* `start` is the index where the slice begins (**inclusive**).
15+
* `stop` is the index where the slice ends (**exclusive**).
16+
17+
For example, if `text = 'Python'`, then `text[0:2]` gives `'Py'`.
18+
19+
Define `employee_code` as `'DEV-2026-JD-001'`. After that, create a variable `department` and assign it the slice of `employee_code` from index `0` to `3`. Then print `department` to the terminal.
20+
21+
# --hints--
22+
You should have a variable named `employee_code`.
23+
24+
```js
25+
({ test: () => assert(runPython(`_Node(_code).has_variable("employee_code")`)) })
26+
```
27+
28+
You should assign the string `DEV-2026-JD-001` to your `employee_code` variable.
29+
30+
```js
31+
({ test: () => assert(runPython(`_Node(_code).find_variable("employee_code").is_equivalent("employee_code = 'DEV-2026-JD-001'")`)) })
32+
```
33+
34+
You should have a variable named `department`.
35+
36+
```js
37+
({ test: () => assert(runPython(`_Node(_code).has_variable("department")`)) })
38+
```
39+
40+
You should slice the first three characters of `employee_code` and assign them to your `department` variable.
41+
42+
```js
43+
({ test: () => runPython(`
44+
dep = _Node(_code).find_variable("department")
45+
assert dep.is_equivalent("department = employee_code[0:3]") or dep.is_equivalent("department = employee_code[:3]")
46+
`) })
47+
```
48+
49+
You should print `department` to the terminal.
50+
51+
```js
52+
({ test: () => assert(runPython(`_Node(_code).has_call("print(department)")`)) })
53+
```
54+
55+
# --seed--
56+
57+
## --seed-contents--
58+
59+
```python
60+
first_name = 'John'
61+
last_name = 'Doe'
62+
full_name = first_name + ' ' + last_name
63+
address = '123 Main Street'
64+
address += ', Apartment 4B'
65+
employee_age = 28
66+
employee_info = full_name + ' is ' + str(employee_age) + ' years old'
67+
print(employee_info)
68+
years_experience = 5
69+
experience_years = 5
70+
experience_info = 'Experience: ' + str(experience_years) + ' years'
71+
print(experience_info)
72+
position = 'Data Analyst'
73+
salary = 75000
74+
employee_card = f'Employee: {full_name} | Age: {employee_age} | Position: {position} | Salary: ${salary}'
75+
print(employee_card)
76+
77+
--fcc-editable-region--
78+
79+
--fcc-editable-region--
80+
```

0 commit comments

Comments
 (0)