In: Computer Science
(previous program) Prompt the user for the filename. Create a new file object sensehat_data_file which opens the file in write mode. Write a loop which will read in 20 values for temperature and humidity from the SenseHat. Sleep 0.5 seconds between each reading taken from the SenseHat Write out the temperature and humidity to the file sensehat_data_file, separated by a comma. Close the file.)
ONLY ANWSER problem below
Then Open the file in read only mode. Use a loop to read in the data from the file until all lines have been read. Print out the count for the number of the line read in. Print out the temperature and humidity.
Print in Python .
Program plan:
Program:
def printFromFile(filename):
f = open(filename, "r")
count = 0
data = []
while True:
line = f.readline()
if not line:
break
line = line[:-1].split(",")
data.append(line)
count+=1
print("Number of lines read: ", count)
for x in data:
print(f"temperature: {x[0]}, humidity: {x[1]}")
Sample output:
If you need any more information, please reach out to me in comments