Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Projects
  3. Build a Weather Data Analyzer in Python

Project 8 · Guided build

Build a Weather Data Analyzer in Python

Analyze a fixed set of daily temperatures and rainfall values with totals, averages, extremes, and simple reporting.

Open the compilerWarm-up exercises
intermediate75–90 minuteslists of dictionariesstatisticsfilteringformatting
On this page
  1. What you will build
  2. Sample data
  3. Averages
  4. Extremes
  5. Rainfall
  6. Text chart
  7. Validation
  8. Extending the analysis
  9. Testing checklist

Working with sample data avoids network dependency while still exercising real analysis skills. You will analyze one month of daily weather records and produce a report.

What you will build#

Given records with a day, high temperature, low temperature, and rainfall, the program will:

  • Print the number of days.
  • Compute the average high and low.
  • Find the hottest and coldest days.
  • Total the rainfall.
  • Count rainy days above a threshold.
  • Print a simple text chart of daily highs.

Sample data#

Python
records = [
    {"day": 1, "high": 18, "low": 9, "rain": 0.0},
    {"day": 2, "high": 21, "low": 11, "rain": 2.4},
    {"day": 3, "high": 19, "low": 10, "rain": 0.0},
    {"day": 4, "high": 16, "low": 8, "rain": 8.1},
    {"day": 5, "high": 23, "low": 12, "rain": 0.0},
    {"day": 6, "high": 25, "low": 14, "rain": 0.0},
    {"day": 7, "high": 22, "low": 13, "rain": 1.2},
]

Use a longer list for practice, but keep the structure identical. A list of dictionaries is easy to read and maps naturally to JSON later.

Averages#

Python
if not records:
    raise SystemExit("No weather records supplied")

average_high = sum(record["high"] for record in records) / len(records)
average_low = sum(record["low"] for record in records) / len(records)

print(f"Average high: {average_high:.1f}")
print(f"Average low:  {average_low:.1f}")

The guard prevents division by zero. SystemExit ends the script cleanly; in a function, you might return None or raise a custom exception instead.

Extremes#

Python
hottest = max(records, key=lambda record: record["high"])
coldest = min(records, key=lambda record: record["low"])

print(f"Hottest day: day {hottest['day']} ({hottest['high']}°)")
print(f"Coldest day: day {coldest['day']} ({coldest['low']}°)")

max() and min() return the whole record, not just the number. That lets the report mention the day.

Ties return the first record encountered. If you need all tied days, filter for records matching the extreme value.

Rainfall#

Python
total_rain = sum(record["rain"] for record in records)
rainy_days = [record for record in records if record["rain"] > 0]
heavy_days = [record for record in records if record["rain"] >= 5]

print(f"Total rainfall: {total_rain:.1f} mm")
print(f"Days with rain: {len(rainy_days)}")
print(f"Heavy rain days: {len(heavy_days)}")

Define the threshold in one named constant so the rule is visible:

Python
HEAVY_RAIN_MM = 5.0

Text chart#

A horizontal bar chart is a good exercise in string formatting:

Python
print("\nDaily highs")
for record in records:
    bar = "#" * record["high"]
    print(f"{record['day']:>2} | {bar} {record['high']}°")

The bar length equals the temperature, which is fine for values around 20. For a wider range, scale the bar:

Python
width = 40
highest = max(record["high"] for record in records)
bar_length = round(record["high"] / highest * width)

Guard against a highest value of zero before dividing.

Validation#

Real data can be missing or malformed. For this fixed dataset, validate the shape before analysis:

Python
required = {"day", "high", "low", "rain"}

for record in records:
    missing = required - record.keys()
    if missing:
        raise ValueError(f"Record is missing {sorted(missing)}")

    if record["high"] < record["low"]:
        raise ValueError(f"High is below low on day {record['day']}")

    if record["rain"] < 0:
        raise ValueError(f"Rainfall cannot be negative on day {record['day']}")

Validation code is not glamorous, but it prevents meaningless averages.

Extending the analysis#

  • Group by week and print a summary per week.
  • Count days above 20° using a comprehension.
  • Compute the difference between high and low for each day and find the largest swing.
  • Add a second dataset for another month and compare averages.
  • Read records from JSON text with json.loads and validate the type of each field.

Separate calculation from presentation

Write functions such as average_high(records) and rainy_days(records) that return numbers or lists. Print from a separate report function. This makes the calculations easy to test and reuse.

Testing checklist#

  • Run with the seven-day sample and verify each number by hand.
  • Try a single-day list.
  • Test an empty list and confirm a clear message.
  • Check the tie behaviour for hottest day.
  • Break one record's fields deliberately and confirm validation catches it.
Previous projectBuild a Text Adventure in PythonNext projectBuild a Bank Account Manager with Classes

On this page

  1. What you will build
  2. Sample data
  3. Averages
  4. Extremes
  5. Rainfall
  6. Text chart
  7. Validation
  8. Extending the analysis
  9. Testing checklist

Project checklist

  • Read the requirements.
  • Plan the data model.
  • Build one feature at a time.
  • Test invalid input.
  • Refactor after it works.