Skip to content

Commit 9cabe20

Browse files
committed
exercise 2
1 parent 18271b3 commit 9cabe20

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

5. string/exercise 2/README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Exercise 2
2+
3+
Using the Template class from the string built-in module create an email template. Sample e-mail below:
4+
5+
```
6+
{
7+
Hello John,
8+
9+
Thank you for visiting our website.
10+
Team, XYZ
11+
}
12+
```
13+
14+
The template should allow you to change the name in the first line of the message.
15+
16+
Then for the following list:
17+
18+
```python
19+
names = ['John', 'Paul', 'Lisa', 'Michael']
20+
```
21+
22+
print the content of personalized emails to the console. Separate each e-mail with a line consisting of 35 characters '-'.
23+
24+
## Expected result
25+
26+
```cmd
27+
Hello John,
28+
29+
Thank you for visiting our website.
30+
Team, XYZ
31+
-----------------------------------
32+
Hello Paul,
33+
34+
Thank you for visiting our website.
35+
Team, XYZ
36+
-----------------------------------
37+
Hello Lisa,
38+
39+
Thank you for visiting our website.
40+
Team, XYZ
41+
-----------------------------------
42+
Hello Michael,
43+
44+
Thank you for visiting our website.
45+
Team, XYZ
46+
-----------------------------------
47+
48+
```

5. string/exercise 2/exercise.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from string import Template
2+
3+
names = ['John', 'Paul', 'Lisa', 'Michael']

5. string/exercise 2/solution.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from string import Template
2+
3+
4+
names = ['John', 'Paul', 'Lisa', 'Michael']
5+
6+
email = """Hello $name,
7+
8+
Thank you for visiting our website.
9+
Team, XYZ"""
10+
11+
template = Template(email)
12+
13+
for name in names:
14+
print(template.substitute(name=name))
15+
print('-' * 35)

0 commit comments

Comments
 (0)