def read_readings(filename):
values = []
with open(filename, "r", encoding="utf-8") as source:
for line in source:
text = line.strip()
if text != "":
values.append(int(text))
return values
def count_high(values, threshold):
count = 0
for value in values:
if value >= threshold:
count = count + 1
return count
# ValueError means the text cannot be converted as requested; do not silently replace it with zero.
values = []
for line in ["24", "bad", "27"]:
try:
values.append(int(line))
except ValueError:
print("invalid", line)
print(values)
# Validation checks whether data meets a rule; it does not prove the sensor was accurate.
readings = [-5, 24, 80]
valid = []
for reading in readings:
if 0 <= reading <= 50:
valid.append(reading)
print(valid)