-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_strings.py
More file actions
24 lines (18 loc) · 846 Bytes
/
02_strings.py
File metadata and controls
24 lines (18 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Exercise 02 — String methods & slicing.
Tutorial: https://pythonbeginner.help/learn/
TODO: given `phrase`, produce:
1. `shout` -> the phrase in UPPERCASE
2. `first5` -> the first 5 characters
3. `words` -> a list of the words
Run: python exercises/02_strings.py
"""
phrase = "python is fun"
# --- your code below -------------------------------------------------------
shout = ... # TODO: phrase.upper()
first5 = ... # TODO: phrase[0:5]
words = ... # TODO: phrase.split()
# --- self-check (don't edit) ----------------------------------------------
assert shout == "PYTHON IS FUN", "shout should be the phrase uppercased"
assert first5 == "pytho", "first5 should be the first 5 characters"
assert words == ["python", "is", "fun"], "words should be the split words"
print("✅ Passed!", shout, "|", first5, "|", words)