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
Samuel was hired to create a program that asks the user questions and, based on the answers, recommend a book to read. What kind
quester [9]

Answer:

I think the answer is C

Explanation:

Selection

3 0
3 years ago
chapter tests and exams are password protected and must be taken in the lab with a universal kiosk browser
Nesterboy [21]

Yes, when a universal kiosk browser (chrome books) being used in the lab during test and exams is protected by avoiding the students to check the answers in the online.

Explanation:

Universal kiosk browser is helpful to display the content on the web on Chrome books. Chrome books are being safe to make student assessment processes. With the help of this, accessing websites to find the answer to the questions in the assessment process by the student is being avoided.

4 0
3 years ago
A company wants to ensure that the validity of publicly trusted certificates used by its web server can be determined even durin
Natali [406]

Answer: OCSP

Explanation:

Ocsp(online certificate status protocol) is used to maintain the security status of the server and also to determine the status of SSL/TLS certificates used by the webserver.

5 0
3 years ago
Luckas entered the date 9-17-2013 in an Excel workbook. He wants the date to appears as “Tuesday, September 17, 2013.” Instead o
irakobra [83]

Explanation:

highlight, correct format and click ok

3 0
3 years ago
Before you buy something you want, you should buy ___ ?
juin [17]

Answer:

The things you need.

Explanation:

People, today, are immersed in a capitalist and consumerist world that is constantly inducing the individual to acquire goods and services, that is, it transforms the individual into a consumer, being the fundamental link for the functioning of consumer societies .

Now, it is necessary that the individual, as a consumer, interprets his own needs and does not get carried away by the constant and overwhelming advertisements that companies launch on the market. In this way, he can cover his basic needs and then consume products that do not have that primary need.

8 0
3 years ago
Other questions:
  • What's a qat on a computer
    12·2 answers
  • Both the USB flash drive and the DVD are data storage devices, but they both have numerous differences. Both can contain insane
    6·1 answer
  • Which command can be used to manually add a package to the driver store?
    13·1 answer
  • What is a biometric scanner?
    8·2 answers
  • What is after Windows 8.1
    11·2 answers
  • Which do web servers host?<br> Websites<br> Networks<br> Firewalls<br> Zones
    8·1 answer
  • As part of the systems engineering development team, use IDEF0 to develop a functional architecture. The functional architecture
    13·1 answer
  • Which of the following is most likely to be considered plagiarism? Using materials from a source without proper citation. Adding
    5·1 answer
  • What is a type of machine-to-human communication?
    14·1 answer
  • Look at the slide.
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!