44 lines
1002 B
Markdown
44 lines
1002 B
Markdown
---
|
|
type: challenge
|
|
title: "The Methods"
|
|
xp: 50
|
|
duration: 30
|
|
difficulty: 2
|
|
---
|
|
|
|
# The Methods
|
|
|
|
> **[INCOMING — Mission Control, Earth]**
|
|
>
|
|
> Cadet, every string carries a toolkit of methods. The most-used:
|
|
>
|
|
> - `s.upper()` — uppercase copy
|
|
> - `s.lower()` — lowercase copy
|
|
> - `s.strip()` — drops leading/trailing whitespace
|
|
> - `s.replace(a, b)` — every `a` becomes `b`
|
|
>
|
|
> Methods can be *chained* — each returns a new string you can call
|
|
> the next on:
|
|
>
|
|
> ```python
|
|
> " Hello World ".strip().lower().replace(" ", "_")
|
|
> # → "hello_world"
|
|
> ```
|
|
>
|
|
> Implement `transform(s)` that returns a dict with three keys:
|
|
>
|
|
> - `upper` — input uppercased
|
|
> - `lower` — input lowercased
|
|
> - `clean` — input stripped, lowercased, spaces replaced by `_`
|
|
>
|
|
> [END TRANSMISSION]
|
|
|
|
## Your Task
|
|
|
|
In `starter/starter.py`, build the dict using the four methods.
|
|
|
|
## Objectives
|
|
|
|
- `transform(" Hello World ")["clean"]` returns `"hello_world"`
|
|
- All three keys present and correct for any string
|