1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rama09 [41]
3 years ago
8

Write a function maxTemp which takes a filename as string argument and returns the maximum temperature as float type for the wee

k. Input file will contain temperature readings for each day of the week. Your function should read each line from the given filename, parse and process the data, and return the required information. Your function should return the highest temperature for the whole week. Empty lines do not count as entries, and should be ignored. If the input file cannot be opened, return -1. Remember temperature readings can be decimal and negative numbers.
Computers and Technology
1 answer:
vichka [17]3 years ago
4 0

Answer:

The solution is written in Python 3

  1. def maxTemp(fileName):
  2.    try:
  3.        with open(fileName) as file:
  4.            raw_data = file.readlines()
  5.            highest = 0
  6.            for row in raw_data:
  7.                if(row == "\n"):
  8.                    continue
  9.                
  10.                data = float(row)
  11.                if(highest < data):
  12.                    highest = data
  13.            return highest
  14.    except FileNotFoundError as found_error:
  15.        return -1
  16. higestTemp = maxTemp("text1.txt")
  17. print(higestTemp)

Explanation:

Firstly, create a function maxTemp that take one input file name (Line 1). Next create an exception handling try and except block to handle the situation when the read file is not found or cannot be open, it shall return -1 (Line 2, Line 15 -16).

Next use the readlines method to read the temperature data from the input file (Line 4). Before we traverse the read data using for loop, we create a variable highest to hold the value of max temperature (Line 5). Let's set it as zero in the first place.

Then use for loop to read the temp data line by line (Line 6) and if there is any empty line (Line 7) just ignore and proceed to the next iteration (Line 7 -8). Otherwise, the current row reading will be parsed to float type (Line 10) and the parsed data will be check with the current highest value. If current highest value is bigger than the current parsed data (), the program will set the parse data to highest variable (Line 11 -12).

After finishing the loop, return the highest as output (Line 14).  

You might be interested in
Discuss what technologies you might see in use at an enterprise. For example, where would you most likely see fiber-optic Ethern
kvv77 [185]

There are various connectivity technologies that we use to connect. They are Ethernet, Internet (Wireless Connection), Bluetooth, Wi-Fi and Cellular.

Explanation:

  • Ethernet is the direct connection among the devices that are located close to each other in a building. This is used for small scale enterprises.
  • Wi-Fi lets wireless connections among multiple devices without any physical connection. And it is most extensively used in most of the corporate companies.
  • Bluetooth is used to transfer the data from one device to the other when they are near.
  • Cellular is used to connect people across the globe. And it is used widely in every enterprises.
7 0
3 years ago
What basic drafting instruments are incorporated in a drafting machine?
erastovalidia [21]
It would be the army and then people of nyc
3 0
3 years ago
What are some of the strategies that you use for confronting a complex problem and breaking it down into smaller pieces? How mig
bazaltina [42]

Answer:

Breaking it down I guess for me, you could take down all the possible things that you could do. Eliminating things, one by one. It could help working on a computer by not letting yourself get over-whelmed by all your programming and thinking "alright, this THEN this."

Explanation:

8 0
3 years ago
Saturn has an orbital period of 29.46 years
Alona [7]

This is true. I'm not sure what you're asking here, but if it's a true/false statement, it's true.

3 0
4 years ago
Read 2 more answers
A. The &lt;hr&gt; tag is an ______ element​
zavuch27 [327]
The element is used to represent a thematic break between paragraph-level elements. It is typically rendered as a horizontal line.

Read more: https://html.com/tags/hr/#ixzz6nqIyUV74
4 0
3 years ago
Read 2 more answers
Other questions:
  • Which method of encryption is based on physics principles?
    5·1 answer
  • Jemima is reviewing her history report and notices that her headings are not formatted the same throughout the report. She wants
    5·2 answers
  • Lynn runs the locate command and the results include many files from a directory that she doesn't want to include in her search.
    9·1 answer
  • Assume that an array named salarySteps whose elements are of type int and that has exactly five elements has already been declar
    11·1 answer
  • True or false: a game design document is like a diary for game developers
    13·2 answers
  • During which phase of film making does the team outline their vision for the film?
    5·1 answer
  • (a) How many copies of the book titled "The Lost Tribe" are owned by the library branch whose name is "Sharpstown"? (b) How many
    10·1 answer
  • WILL GIVE BRAINLEIST PLZ HELP PLZ AND THANK YOU
    7·1 answer
  • If you play video games, please answer these questions it’s for a survey for my game development class!!
    5·1 answer
  • Compare the freedom available to the American media with the freedom available to media in other parts of the world. How does a
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!