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
Yuliya22 [10]
3 years ago
13

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. Each line of the file contains two elements, separated by commas (,) DAY,TEMPERATURE Monday,52 Note: The split() function is provided, and functions as it does in the homework assignments, to make parsing the output easier. Recall that split takes a string s and splits it at the input delimiter sep, to fill the array words[] up to a capacity of max_words. The return value of split is the number of actual words the string is split into.

Computers and Technology
1 answer:
Alenkinab [10]3 years ago
8 0

Answer:

#section 1

def maxTemp(filename):

   import pathlib

   f = pathlib.Path(filename)

   f.exists()

   if f.exists():

       f = open(filename, "r")

#section 2

       next(f)

       res = [int(sub.split(',')[1]) for sub in f]

       maxdata = (res[0])

       for i in range(len(res)-1):

           if maxdata < res[i]:

               maxdata = res[i]

       

       index = res.index(maxdata)

       f.close()

 #section 3  

       li = []  

       a = open(filename, "r")

       for line in a:

           line = line.strip()

           li.append(line)

   

       

       a.close()

       return (li[index+1])

   else:

       return -1

print(maxTemp("new.csv"))

Explanation:

#section 1:

The function maxTemp is defined. We import pathlib in other to check if the file exists, if it does we carry on with opening the file and if it doesn't the program returns -1.

#section 2:

We start splitting the sub-lists from the second line i.e <em>next(f)</em>. For each line we take the second index element and convert it to an integer.

<em>res = [int(sub.split(',')[1]) for sub in f] </em>

The maximum number is gotten by using the if statement to compare all elements in the list.  The index of the maximum item in the list is collected.

the file is then closed.

#section 3  :

The file is re-opened and all the lines are striped and passed into a new list and the index recovered from section 2, is used to get the day with the highest temperature and the line is returned.

You might be interested in
The conversion of decimal 0.0625 into its binary equivalent. Explain.
Rashid [163]
D. 0.0001.......first the zero before the decimal point is devided by 2....so it gives out 0 as a reminder so u right 0. at first then to do the part after decimal...first multiply 0.625 by 2 which gives out 0.125 as a fractional number so 0 would be the number after "0." ...and again the answer 0.125 is multiplied by 2 which gives out 0.25....so again we get a zero as an integer so now it would be "0.00..." ....again multiply 0.25 by 2 which gives out 0.5....again the integer is 0....so we add another 0 after 0.00....which would then become 0.000.....after that again multiply 0.5 by 2 which would give 1 as a result....as the fractional part is over, u need to stop here....so add that 1 after the 0.000 which gives 0.0001 as a final result.
4 0
4 years ago
The transmission method that sends data to every device on a lan is known as a _____ transmission.
lina2011 [118]
The transmission method that sends data to every device on a lan is known as a broadcast transmission. This type of transmission is also referred toa as <span> one-to-all transmission method. The network carries a message to all devices at the same time.
</span><span>Sometimes broadcasts are a result of network devices continually announcing their presence in the network, so that other devices don't forget who is still a part of the network.</span>
4 0
4 years ago
Read 2 more answers
Can someone urgently help me with my java code? Ive been working on it for hours and its not working.
Paha777 [63]

Answer:

nm hn hhjjnjjnj j

Explanation:

kjnjnjn jnjubhvcfv

3 0
3 years ago
The most basic function of firewalls is to
adelina 88 [10]
<span>A firewall is a network security system that monitors and controls the incoming and outgoing network traffic based on security rules that are configured by the network administrator.</span>
5 0
3 years ago
Select all that apply.
Ierofanga [76]
Insert option the last one
3 0
3 years ago
Read 2 more answers
Other questions:
  • SP 800-14, Generally Accepted Principles and Practices for Securing Information Technology Systems, provides best practices and
    12·1 answer
  • If you need to reprogramming your gps after you begin driving __.
    15·2 answers
  • Submit your 300-word essay describing the equipment usedI in a well-equipped studio’s audio department and the training and expe
    8·2 answers
  • In the dewey decimal sysytem, the call number 800 notes which section
    10·1 answer
  • Under the Right to Know Rule, employers need to include information on which one of the following in a written and complete haza
    5·1 answer
  • Exactly how thin is the air in outer space?
    10·1 answer
  • Henry is nervous speaking in public, and it shows every time he presents his ideas to his coworkers and manager. One of his team
    6·2 answers
  • What is the decrypted binary
    9·1 answer
  • Help Me Please, Ill mark whoever has the best answer with brainliest.
    14·1 answer
  • A line graph is a great tool for showing changes over time. Why is a line graph better than other graphs at showing this type of
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!