seed: curriculum content
This commit is contained in:
44
1.solar-system/2.first-light/09.the-temperature/index.md
Normal file
44
1.solar-system/2.first-light/09.the-temperature/index.md
Normal file
@@ -0,0 +1,44 @@
|
||||
---
|
||||
type: challenge
|
||||
title: "The Temperature"
|
||||
xp: 75
|
||||
duration: 30
|
||||
difficulty: 2
|
||||
---
|
||||
|
||||
# The Temperature
|
||||
|
||||
> **[INCOMING — Mission Control, Earth]**
|
||||
>
|
||||
> Cadet, half the world reads temperature in Fahrenheit, the other
|
||||
> half in Celsius. Build a converter.
|
||||
>
|
||||
> Formula: `C = (F - 32) * 5 / 9`
|
||||
>
|
||||
> Implement `f_to_c(f)` that returns a string of the form:
|
||||
>
|
||||
> ```
|
||||
> <F>°F = <C>°C
|
||||
> ```
|
||||
>
|
||||
> Where `<C>` is rounded to one decimal place using `:.1f`. Convert
|
||||
> the input with `float()` first so the output is consistent for
|
||||
> int and float inputs.
|
||||
>
|
||||
> Examples:
|
||||
>
|
||||
> - `f_to_c(32)` → `"32.0°F = 0.0°C"`
|
||||
> - `f_to_c(212)` → `"212.0°F = 100.0°C"`
|
||||
> - `f_to_c(98.6)` → `"98.6°F = 37.0°C"`
|
||||
>
|
||||
> [END TRANSMISSION]
|
||||
|
||||
## Your Task
|
||||
|
||||
In `starter/starter.py`, convert `f` to float, compute Celsius,
|
||||
return the formatted string.
|
||||
|
||||
## Objectives
|
||||
|
||||
- All three examples produce the exact expected string
|
||||
- Works for any numeric F input
|
||||
@@ -0,0 +1,13 @@
|
||||
def f_to_c(f):
|
||||
"""Convert Fahrenheit to Celsius and return a formatted string.
|
||||
|
||||
Formula: C = (F - 32) * 5 / 9
|
||||
|
||||
The Celsius value should be formatted with 1 decimal place.
|
||||
Convert the Fahrenheit input with float() so output is consistent.
|
||||
|
||||
f_to_c(32) -> "32.0°F = 0.0°C"
|
||||
f_to_c(212) -> "212.0°F = 100.0°C"
|
||||
f_to_c(98.6) -> "98.6°F = 37.0°C"
|
||||
"""
|
||||
pass
|
||||
@@ -0,0 +1,17 @@
|
||||
from solution import f_to_c
|
||||
|
||||
|
||||
def test_freezing():
|
||||
assert f_to_c(32) == "32.0°F = 0.0°C"
|
||||
|
||||
|
||||
def test_boiling():
|
||||
assert f_to_c(212) == "212.0°F = 100.0°C"
|
||||
|
||||
|
||||
def test_body_temp():
|
||||
assert f_to_c(98.6) == "98.6°F = 37.0°C"
|
||||
|
||||
|
||||
def test_zero_fahrenheit():
|
||||
assert f_to_c(0) == "0.0°F = -17.8°C"
|
||||
Reference in New Issue
Block a user