Today's Temperatures
Time for a small project! In this checkpoint, you'll write a whole program on your own, using what you've learned in the first three lessons: variables, numbers and the math functions, string.format and conditions.
The exercises here are a bit different from the ones so far. The instructions say what the program should print, not how to write it. There are many correct ways, so pick the one that makes sense to you. If you get stuck, look back at the lesson where you learned what you need.
The project. Emma keeps a thermometer on the wall of the barn, and every evening she wants to know what the day was like. Over three exercises, your program will turn the day's readings into a weather report: the temperatures, what kind of day it was, and whether Emma should water the field. Each exercise continues where the previous one ended: the editor starts with a finished program from the previous step, which may look different from yours. That's fine.
The data. The variables at the top of the program hold the temperatures that Emma read in the morning, in the afternoon and in the evening, in °C. On a big farm, a weather station would measure them. Here, the program gets them from the variables, and your code should work with the variables, not with their numbers copied into it: when you change a variable, the program should still print the right result. To check that, each exercise also runs your program with other values, and it has to get those right too.
The task. Print the lowest and the highest of the three temperatures, and their average with one decimal place. For today, the program prints:
Lowest: 5 °C
Highest: 17 °C
Average: 10.3 °CThe average is the three temperatures added up and divided by 3: 31 / 3 is 10.333…, which is 10.3 with one decimal place. Don't count on the morning being the coldest and the afternoon the warmest, though. After a cold front, it can be 12 °C in the morning and only 3 °C in the evening.
A tip: remember math.min and math.max from the lesson on variables, and %.1f in string.format.
Instructions
Print the lowest and the highest temperature, as in the example.
Below that, print the average temperature, with one decimal place.
Start programming for free
1/3