seed: curriculum content
This commit is contained in:
42
1.solar-system/3.strings/01.the-message/index.md
Normal file
42
1.solar-system/3.strings/01.the-message/index.md
Normal file
@@ -0,0 +1,42 @@
|
||||
---
|
||||
type: challenge
|
||||
title: "The Message"
|
||||
xp: 50
|
||||
duration: 25
|
||||
difficulty: 2
|
||||
---
|
||||
|
||||
# The Message
|
||||
|
||||
> **[INCOMING — Mission Control, Earth]**
|
||||
>
|
||||
> Cadet, a string is a *sequence of characters*. You can pick any
|
||||
> one out by its position (its *index*).
|
||||
>
|
||||
> Indexes start at 0:
|
||||
>
|
||||
> ```
|
||||
> M I S S I O N
|
||||
> 0 1 2 3 4 5 6
|
||||
> ```
|
||||
>
|
||||
> Negative indexes count back from the end. `s[-1]` is the last
|
||||
> character.
|
||||
>
|
||||
> Strings are *immutable* — you can read any character, but you can't
|
||||
> change one in place. To "modify" a string, you build a new one.
|
||||
>
|
||||
> Implement `info(s)` that returns a dict with four keys: `first`,
|
||||
> `sixth`, `last`, `length`.
|
||||
>
|
||||
> [END TRANSMISSION]
|
||||
|
||||
## Your Task
|
||||
|
||||
Open `starter/starter.py`. Use `s[0]`, `s[5]`, `s[-1]`, and `len(s)`
|
||||
to fill in the dict.
|
||||
|
||||
## Objectives
|
||||
|
||||
- `info("MISSION-CONTROL-7")` returns `{"first": "M", "sixth": "O", "last": "7", "length": 17}`
|
||||
- Works for any non-empty string of length ≥ 6
|
||||
13
1.solar-system/3.strings/01.the-message/starter/starter.py
Normal file
13
1.solar-system/3.strings/01.the-message/starter/starter.py
Normal file
@@ -0,0 +1,13 @@
|
||||
def info(s):
|
||||
"""Return a dict describing the string s.
|
||||
|
||||
Keys:
|
||||
"first" — the character at index 0
|
||||
"sixth" — the character at index 5
|
||||
"last" — the character at index -1
|
||||
"length" — total number of characters
|
||||
|
||||
info("MISSION-CONTROL-7") -> {"first": "M", "sixth": "O",
|
||||
"last": "7", "length": 17}
|
||||
"""
|
||||
pass
|
||||
@@ -0,0 +1,16 @@
|
||||
from solution import info
|
||||
|
||||
|
||||
def test_mission_control():
|
||||
r = info("MISSION-CONTROL-7")
|
||||
assert r == {"first": "M", "sixth": "O", "last": "7", "length": 17}
|
||||
|
||||
|
||||
def test_andromeda():
|
||||
r = info("andromeda")
|
||||
assert r == {"first": "a", "sixth": "m", "last": "a", "length": 9}
|
||||
|
||||
|
||||
def test_alphabet():
|
||||
r = info("ABCDEFGH")
|
||||
assert r == {"first": "A", "sixth": "F", "last": "H", "length": 8}
|
||||
Reference in New Issue
Block a user