neil.gordon@hey.com
Write a python function that converts a two digit WMO Present Weather code to a text description of the weather. Base it on the following table only: WMO Weather interpretation codes (WW) Code Description 0 Clear sky 1, 2, 3 Mainly clear, partly cloudy, and overcast 45, 48 Fog and depositing rime fog 51, 53, 55 Drizzle: Light, moderate, and dense intensity 56, 57 Freezing Drizzle: Light and dense intensity 61, 63, 65 Rain: Slight, moderate and heavy intensity 66, 67 Freezing Rain: Light and heavy intensity 71, 73, 75 Snow fall: Slight, moderate, and heavy intensity 77 Snow grains 80, 81, 82 Rain showers: Slight, moderate, and violent 85, 86 Snow showers slight and heavy 95 * Thunderstorm: Slight or moderate 96, 99 * Thunderstorm with slight and heavy hail
def wmo_weather_code(code): weather_codes = { 0: "Clear sky", 1: "Mainly clear", 2: "Partly cloudy", 3: "Overcast", 45: "Fog", 48: "Depositing rime fog", 51: "Drizzle: Light intensity", 53: "Drizzle: Moderate intensity", 55: "Drizzle: Dense intensity", 56: "Freezing Drizzle: Light intensity", 57: "Freezing Drizzle: Dense intensity", 61: "Rain: Slight intensity", 63: "Rain: Moderate intensity", 65: "Rain: Heavy intensity", 66: "Freezing Rain: Light intensity", 67: "Freezing Rain: Heavy intensity", 71: "Snow fall: Slight intensity", 73: "Snow fall: Moderate intensity", 75: "Snow fall: Heavy intensity", 77: "Snow grains", 80: "Rain showers: Slight intensity", 81: "Rain showers: Moderate intensity", 82: "Rain showers: Violent intensity", 85: "Snow showers: Slight intensity", 86: "Snow showers: Heavy intensity", 95: "Thunderstorm: Slight or moderate", 96: "Thunderstorm with slight hail", 99: "Thunderstorm with heavy hail" } return weather_codes.get(code, "Invalid code")

The function takes a two digit WMO weather code as input and returns a string describing the weather based on the code. If the code is not in the table, the function will return "Invalid code".

neil.gordon@hey.com
That's good, but I'd like all the intensity descriptors to be turned around so that, for instance "Freezing Drizzle: Light intensity" becomes "Light Freezing Drizzle"
def wmo_weather_code(code): weather_codes = { 0: "Clear sky", 1: "Mainly clear", 2: "Partly cloudy", 3: "Overcast", 45: "Fog", 48: "Depositing rime fog", 51: "Light Drizzle", 53: "Moderate Drizzle", 55: "Dense Drizzle", 56: "Light Freezing Drizzle", 57: "Dense Freezing Drizzle", 61: "Slight Rain", 63: "Moderate Rain", 65: "Heavy Rain", 66: "Light Freezing Rain", 67: "Heavy Freezing Rain", 71: "Slight Snow fall", 73: "Moderate Snow fall", 75: "Heavy Snow fall", 77: "Snow grains", 80: "Slight Rain showers", 81: "Moderate Rain showers", 82: "Violent Rain showers", 85: "Slight Snow showers", 86: "Heavy Snow showers", 95: "Thunderstorm: Slight or moderate", 96: "Thunderstorm with slight hail", 99: "Thunderstorm with heavy hail" } return weather_codes.get(code, "Invalid code")

This is the updated function with the intensity descriptor in the correct place, now the output will be "Light Freezing Drizzle" for example.

neil.gordon@hey.com
Great - just a few more changes - I don't want "fall" after "Snow:" anywhere, and "showers" and "grains" should be capitalised, and code 95 can just be Thunderstorm"
def wmo_weather_code(code): weather_codes = { 0: "Clear sky", 1: "Mainly clear", 2: "Partly cloudy", 3: "Overcast", 45: "Fog", 48: "Depositing rime fog", 51: "Light Drizzle", 53: "Moderate Drizzle", 55: "Dense Drizzle", 56: "Light Freezing Drizzle", 57: "Dense Freezing Drizzle", 61: "Slight Rain", 63: "Moderate Rain", 65: "Heavy Rain", 66: "Light Freezing Rain", 67: "Heavy Freezing Rain", 71: "Slight Snow", 73: "Moderate Snow", 75: "Heavy Snow", 77: "Snow Grains", 80: "Slight Rain Showers", 81: "Moderate Rain Showers", 82: "Violent Rain Showers", 85: "Slight Snow Showers", 86: "Heavy Snow Showers", 95: "Thunderstorm", 96: "Thunderstorm with slight hail", 99: "Thunderstorm with heavy hail" } return weather_codes.get(code, "Invalid code")

This is the updated function that incorporates the changes you requested:

  • "fall" removed after "Snow:"
  • "showers" and "grains" capitalised
  • code 95 is now just "Thunderstorm"

Please let me know if there is anything else I can help you with.

Generated With ChatGPT Export
ChatGPT Jan 9 Version. Free Research Preview. Our goal is to make AI systems more natural and safe to interact with. Your feedback will help us improve.