"""Challenge 95: Environmental data detective; threshold is inclusive."""
import csv

def analyse(path, threshold):
    with open(path, newline="", encoding="utf-8") as stream:
        values = [float(row["temperature_c"]) for row in csv.DictReader(stream)]
    if not values:
        raise ValueError("No readings in the file")
    return (min(values), max(values), sum(values) / len(values),
            sum(value >= threshold for value in values))

def main():
    threshold = float(input("Alert threshold (°C): "))
    low, high, average, alerts = analyse("environment.csv", threshold)
    print(f"Minimum: {low:.1f}°C | Maximum: {high:.1f}°C")
    print(f"Mean: {average:.1f}°C | At/above threshold: {alerts}")

if __name__ == "__main__":
    main()
