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
All NATE specialties are offered at two levels, A. journeyman and master. B. installation and service. C. apprentice and journey
Rainbow [258]

Answer:

D. heating and air conditioning.

Explanation:

NATE is a business that declares specialists in the heating system, ventilation, and air conditioning industry.

5 0
3 years ago
When using a wireless mouse, what is the most common port used for the transmitter? 
larisa [96]
Your answer is B. USB
7 0
3 years ago
Which of the following is NOT true about a flow chart?
SCORPION-xisa [38]
I think the answer is A
4 0
3 years ago
A user deletes a message from a mailbox while on a desktop. What happens to the email message on the user's synchronized devices
gulaghasi [49]

Answer:

Explanation:

Depends on the configuration of the email because there are two protocols POP and IMAP, the most recent protocol is IMAP, we can delete an email and this It moves to a To be Deleted folder, this happens because the email is stored in the server, but with the protocol POP the email is stored in the server and downloaded to the application, if you delete an email, this is deleted in all devices.

8 0
4 years ago
Read 2 more answers
The document asks about dependents because the number can
BARSIC [14]
The answer is: Lower overall taxes
8 0
3 years ago
Read 2 more answers
Other questions:
  • The manager of a sports club has data about the club members' ages in a workbook. He wants to find which age is most common. Whi
    13·2 answers
  • Allows an administrator to query a dns database and find the host name associated with a specific ip address or
    15·1 answer
  • If your BAL is .10 you can expect a _______ drop in complex performance compared to the sober level
    6·1 answer
  • Plz help me of this answer<br><br><br>language:python​
    7·2 answers
  • Consider a channel that can lose packets but has a maximum delay that is known. Modify Protocol rdt2.1 to include sender timeout
    11·1 answer
  • A byte contains how many bits? Question 3 options:
    13·2 answers
  • What PowerShell command can be used to clean up old update files on a WSUS server, including unused update files, old revisions,
    10·1 answer
  • if a second system failure occurs while the first recovery is in progress, what needs tobe done after the system recovers for th
    11·1 answer
  • Do yall think I should be lonely and quit life!!
    8·2 answers
  • Which statement about routers is !!!FALSE!!!
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!