seed: curriculum content
This commit is contained in:
47
1.solar-system/3.strings/07.the-report/index.md
Normal file
47
1.solar-system/3.strings/07.the-report/index.md
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
type: challenge
|
||||
title: "The Report"
|
||||
xp: 100
|
||||
duration: 35
|
||||
difficulty: 3
|
||||
---
|
||||
|
||||
# The Report
|
||||
|
||||
> **[INCOMING — Mission Control, Earth]**
|
||||
>
|
||||
> Cadet, capstone for the strings module. Combine f-strings,
|
||||
> repetition, methods, and `\n` joining into one formatted output.
|
||||
>
|
||||
> Repetition: `"=" * 30` produces a string of 30 equals signs.
|
||||
>
|
||||
> Implement `format_report(name, status, location, time)` that
|
||||
> returns this exact 8-line report as a single string (lines joined
|
||||
> with `\n`):
|
||||
>
|
||||
> ```
|
||||
> ==============================
|
||||
> MISSION REPORT
|
||||
> ==============================
|
||||
> Name: <NAME IN UPPERCASE>
|
||||
> Status: <status as entered>
|
||||
> Location: <location as entered>
|
||||
> Time: <time as entered>
|
||||
> ==============================
|
||||
> ```
|
||||
>
|
||||
> Only the name is uppercased; other fields print as entered.
|
||||
>
|
||||
> [END TRANSMISSION]
|
||||
|
||||
## Your Task
|
||||
|
||||
In `starter/starter.py`, build the report string. Use `"=" * 30`
|
||||
for borders, `name.upper()` for the name, and join lines with `\n`.
|
||||
|
||||
## Objectives
|
||||
|
||||
- `format_report("apollo", "ok", "moon", "13:32")` returns the
|
||||
exact 8-line string
|
||||
- Only the name is uppercased
|
||||
- Borders are 30 `=` characters
|
||||
19
1.solar-system/3.strings/07.the-report/starter/starter.py
Normal file
19
1.solar-system/3.strings/07.the-report/starter/starter.py
Normal file
@@ -0,0 +1,19 @@
|
||||
def format_report(name, status, location, time):
|
||||
"""Return a formatted mission report as a single string.
|
||||
|
||||
The report is 8 lines, joined by '\n'. The borders are 30 equals
|
||||
signs ("=" * 30). Only the name is uppercased; other fields are
|
||||
inserted as-is.
|
||||
|
||||
format_report("apollo", "ok", "moon", "13:32") returns:
|
||||
|
||||
==============================
|
||||
MISSION REPORT
|
||||
==============================
|
||||
Name: APOLLO
|
||||
Status: ok
|
||||
Location: moon
|
||||
Time: 13:32
|
||||
==============================
|
||||
"""
|
||||
pass
|
||||
@@ -0,0 +1,36 @@
|
||||
from solution import format_report
|
||||
|
||||
|
||||
def test_apollo():
|
||||
expected = (
|
||||
"==============================\n"
|
||||
"MISSION REPORT\n"
|
||||
"==============================\n"
|
||||
"Name: APOLLO\n"
|
||||
"Status: ok\n"
|
||||
"Location: moon\n"
|
||||
"Time: 13:32\n"
|
||||
"=============================="
|
||||
)
|
||||
assert format_report("apollo", "ok", "moon", "13:32") == expected
|
||||
|
||||
|
||||
def test_voyager():
|
||||
result = format_report("voyager", "active", "interstellar", "1977-09-05")
|
||||
assert "Name: VOYAGER" in result
|
||||
assert "Status: active" in result
|
||||
assert "Location: interstellar" in result
|
||||
assert "Time: 1977-09-05" in result
|
||||
assert result.startswith("=" * 30 + "\n")
|
||||
assert result.endswith("\n" + "=" * 30)
|
||||
|
||||
|
||||
def test_perseverance():
|
||||
result = format_report("perseverance", "roving", "jezero crater", "2026-05-04")
|
||||
assert "Name: PERSEVERANCE" in result
|
||||
assert "Location: jezero crater" in result
|
||||
|
||||
|
||||
def test_eight_lines():
|
||||
result = format_report("apollo", "ok", "moon", "13:32")
|
||||
assert result.count("\n") == 7
|
||||
Reference in New Issue
Block a user