To Water or Not?
Should Emma water the field tonight? Two new variables help her decide. rain is how many millimeters of rain fell today. forecast is Grandpa Joe's forecast for tomorrow: he watches the sky every evening and says "rain" or "sun". Today, he hasn't said anything, so forecast has no value: it's nil.
First, print the forecast, or unknown when there's none. Then print how often Emma waters the field:
nonewhen at least 5 millimeters of rain fell today, or when Grandpa Joe forecasts rain;twice, in the morning and in the evening, on a hot day (that's 25 °C or more, as in the previous exercise);onceon any other day.
Rain wins over heat: on a hot day with rain in the forecast, Emma doesn't water at all. For today, the output ends like this:
Day: warm
Frost: no
Forecast: unknown
Watering: onceThe exercise checks the program with other data too, such as a forecast of rain or of sun, or a hot day. So make sure it's right in every case, not only today.
A tip: joining nil to a text ends with an error. In the lesson on conditions, you learned a short way to use a default value instead.
That's the whole project. With just three lessons behind you, you've written a weather report for a farm: it calculates with variables and the math functions, formats numbers, and makes decisions with conditions, even when a value is missing. In the next lesson, on loops, you'll learn to make a program repeat code. Then it could go through the weather of a whole season, not just of one day.
Instructions
Print Grandpa Joe's forecast, or unknown when he hasn't made one.
Below it, print how often Emma waters the field.
Start programming for free
3/3