This program is available online please check on website before posting: http://
ID: 3593910 • Letter: T
Question
This program is available online please check on website before posting: http://www.codestepbystep.com/problem/view/python/fileio/weather
Write a console program that reads an input file of temperatures, with numbers representing daily high temperatures such as:
Your program should prompt for the file name to read, then read its data and print the change in temperature between each pair of neighboring days.
If there are any non-numeric tokens of input in the file, your program should skip over them and ignore them. You may assume that the user types the name of a file that exists and is readable.
Explanation / Answer
link is asking for login so I tried with sample data given
filename = input("Enter file name for temperature data: ")
data = []
with open(filename) as fh:
for line in fh:
linedata = line.split()
for d in linedata:
try:
a = float(d)
data.append(a)
except ValueError:
continue
for i in range(len(data) -1):
change = data[i+1] - data[i]
print("%.1f to %.1f, change = %.1f" % (data[i], data[i+1], change))
# copy pastable code link: https://paste.ee/p/XuQDT
'''
Sample run
Enter file name for temperature data: whether.txt
16.2 to 23.2, change = 7.0
23.2 to 19.2, change = -4.0
19.2 to 7.7, change = -11.5
7.7 to 22.9, change = 15.2
22.9 to 18.4, change = -4.5
18.4 to -1.6, change = -20.0
-1.6 to 14.6, change = 16.2
'''
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.