Python challenge

---

A lunar robot explores the surface of the moon. Using sensors, it takes samples of temperature and stores the data in a simple text file. The data is recorded in degrees Celcius. Here is a sample file.

At the end of each day before the lunar bot shuts down, it runs a program to analyse the data.

It calculates:

  1. the maximum temperature stored in the file
  2. the minimum temperature stored in the file
  3. the number of times the temperature was above 100 degrees Celcius

Task A - READ the contents of the file into a computer program

Save the text file in your project folder. If you are using REPLIT (or similar), upload the file to your programming area.

Type this code into your IDE. It simply reads the file and stores the results in an array:

Task B - Process the data

Here is an attempt at a solution. Some code is missing. Fill the blanks to complete the program:

count ←

min ← dataSet[0]

max ←

FOR i ← 0 TO LEN(dataSet)

IF dataSet[i] < THEN

min ←

IF > max THEN

max ← dataSet[i]

IF dataSet[i] > THEN

count ← count + 1

END WHILE

OUTPUT "MAX :",max,"; MIN: ",min,"; COUNT: ", count

Task C - WRITE to a file

Create a new file called dailyresult.txt.

Can you figure out how to write the results from Task B into this new file? Use the following format:


Tags

Python open file read selection loop sequence condition iteration assignment