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
Wouldn’t it be nice if whenever we messed up our life we could simply press ‘Ctrl Alt Delete’ and start all over?
Orlov [11]
Sure, if you want to delete things
8 0
4 years ago
Read 2 more answers
Students who interact online with others from different cultures should remember that
aliya0001 [1]

Answer:

they are dealing with people, not computers.

8 0
4 years ago
Read 2 more answers
Please help!!!!<br> Data means only facts. <br> A. TRUE B. FALSE
vredina [299]
B false data does not only have to be facts
6 0
3 years ago
Which of the following is a new feature in Windows Server 2016 that enables block-level data replication to occur automatically
Inessa [10]

Answer:

Option C is the correct answer for the above question

Explanation:

  • The storage replica is a new advantage that is used in the 2016 version of the windows server. It is a feature which is very useful for the user point of view, because of it more secure the data transfer on the internet.
  • It is used to block the duplicate data, by which the storage space is left for the other data and the data will secure when it stores on the server.
  • The above question asked about the features which are a new advantage of the 2016 version and provide block facilities for the duplicate data which is storage Replica which is defined above.
  • Hence the correct option is C, while the other is not because others is not a feature to block the duplicate data.
7 0
3 years ago
How is cell phone usage changing American Society? Is this a good change or a bad change? Explain.
klio [65]

Answer:

Causing too many eye problems and changing and influecing people too much. Causes anxiety. BAD

Explanation:

7 0
3 years ago
Other questions:
  • What was Leonardo da Vinci an expert in
    11·1 answer
  • What type of cable is used to connect a workstation serial port to a cisco router console port?
    15·1 answer
  • Which of the following functions sends the the GPA entered by the user to the calling function? A. def get_gpa(): gpa = float(in
    8·1 answer
  • Sharon is thinking about opening a bakery. She knows she wants to set her own hours, reduce her stress and make a profit. But sh
    14·1 answer
  • How do you program a computer
    7·1 answer
  • Three advantages to the company of using robots rather than human to manufacture company​
    13·1 answer
  • Hey im b---o---r---e---d dont report cuz if u do ur l a m e :)
    14·1 answer
  • A flowchart meeting is a process where members of the team analyze the design piece-by-piece to make sure it meets requirements
    15·1 answer
  • How do you code to find the surface area 6 s2, volume s3 in python
    6·1 answer
  • PLEASE HELP. Nobody has been helping me, i need to resolve this code issue for game design
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!