Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

31. (10 pts) Write a complete Python progtam to solve the \"Greatest Temperature

ID: 3705430 • Letter: 3

Question

31. (10 pts) Write a complete Python progtam to solve the "Greatest Temperature Difference Problem" Input to this program are numbers read from the file "leconte.dat". (Yes, you have to "open" that file. Don't forget to "close" it afterwards.) This input consists of a sequence of real nu with one decimal place) representing afternoon. (Use morning and afternoon as your variable names.) To simplify reading these values, the morning value is on a line by itself followed by a second line that holds the afternoon value. So if there were, say, 100 pairs of numbers to be processed, the input file would be exactly 200 lines long. The end of input is marked by the sentinel pair "0.0 0.0 (that is, zero zero); of course, per the description above, each zero would be on a line by itself. and determine which pair represent input other than the sentinel pair, set the biggest change value to zero.) Print the biggest temperature change. The ONLY thing your program needs to print is this greatest temperature difference. Use the usual convention of having a main() routine that you then invoke; do NOT write any other user- defined functions. To minimize your writing, you do not have to code any comments. Note: The morning is not always colder than the afternoon. Thus you might read in the pair "50.0 65.5", which has an absolute difference of 15.5, or you could read in "65.5 50 the same absolute difference. Don't forget the numbers can be negative too. (lt gets cold up on that lount LeConte in the mor Your program must input these pairs ts the greatest change in temperature. (In the event there is no mountainl) For example, the pair 5,0 7.4" (with a difference of 12.4) is legal input.

Explanation / Answer

def main():
with open('leconte.dat', 'r') as f:
diff_list=[]
for line in f:
morning=line.rstrip().lstrip()
afternoon=next(f).rstrip().lstrip()
diff_list.append(abs(round((float(morning)-float(afternoon)),1)))   
f.close()
print(max(diff_list))
main()

##Please save leconte.dat file and this program in same file.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote