38 lines
816 B
Markdown
38 lines
816 B
Markdown
---
|
||
type: challenge
|
||
title: "The Translator"
|
||
xp: 50
|
||
duration: 25
|
||
difficulty: 2
|
||
---
|
||
|
||
# The Translator
|
||
|
||
> **[INCOMING — Mission Control, Earth]**
|
||
>
|
||
> Cadet, when input comes in as text (a `str`), you can't do math
|
||
> with it directly. You have to *translate* it to a number.
|
||
>
|
||
> Three converters:
|
||
>
|
||
> - `int("42")` → `42`
|
||
> - `float("3.14")` → `3.14`
|
||
> - `str(42)` → `"42"`
|
||
>
|
||
> Implement `years_until(age)` that returns `100 - age` as an `int`.
|
||
> The argument may arrive as either `int` or `str` — handle both
|
||
> by calling `int()` on it first.
|
||
>
|
||
> [END TRANSMISSION]
|
||
|
||
## Your Task
|
||
|
||
Open `starter/starter.py`. Convert `age` with `int()`, then return
|
||
`100 - age`.
|
||
|
||
## Objectives
|
||
|
||
- `years_until(25)` returns `75`
|
||
- `years_until("25")` also returns `75` (handles string input)
|
||
- Works for any integer age 0–100
|