Question: Hello, here is the assignment in verbatim: Write a console program that reads an input file of temperatures, with numbers representing daily high temperatures such
Hello, here is the assignment in verbatim: Write a console program that reads an input file of temperatures, with numbers representing daily high temperatures such as:
16.2 23.2 19.2 7.7 22.9 18.4 -1.6 14.6
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.
Input file? weather.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
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. Here's what I have: def weather_change(): the_file = input("Input file? ") file = open(the_file) file = file.read().split() for i in range(0,(len(file)-1)): # difference = (int(file[i+1])-int(file[i])) print(file[i]+" to "+file[i+1]+",change = "+difference) weather_change()
now my problem is that I can't seem to subtract the second number in a pair from the first as I get an error saying that i'm trying to subtract two strings, then when trying to convert the two into int()'s I get a another error claiming an invalid literal. Thanks in advance!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
