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
Felicia is a computer programmer.
dolphi86 [110]

A: SSD, HDD, CPU or RAM

Whether you go with the faster SSD or slower but larger HDD, keep in mind you may end up needing a drive large enough to run a dual boot system if you plan on coding in multiple environments. Virtualization of other operating systems is another option, but that requires a fast CPU and a large amount of RAM to work well.

B: Ram because its larger than the others, and will work better.

C: i don't really have a suggested system but here

You may appreciate the seamless experience iOS offers, the flexibility of Android or the familiarity of Windows with your everyday PC. It might take some time to acclimate to a new system, so it may be best to stick with what you know.

Please consider marking brainliest.. thx

8 0
3 years ago
Which Call of Duty game is the best?
love history [14]

Answer:

i like ghost and modern 3

Explanation:

3 0
3 years ago
Plz answer it’s timed
MAVERICK [17]

Answer: the third one

Explanation:

just trust me, the other ones dont mke sense to what I know about the subject, which is a lot

7 0
2 years ago
2
BaLLatris [955]

Answer:

the control center

Explanation:

<h2><em>hope this helps :)</em></h2>

<em>please make me brainliest\</em>

3 0
2 years ago
When a person initially records information in a form usable to memory, this is called?
MakcuM [25]
Is an answer encoding? 
3 0
3 years ago
Other questions:
  • What is the utility of a lever?
    11·2 answers
  • What are the benefits of public access databases like ncbi? how does?
    11·1 answer
  • Which of the following is good practice to ensure that you do not get malware on your computer from an online source?
    5·1 answer
  • Write a program which capitalize every character after full stopin a given sentence
    11·1 answer
  • A computer program that translates a program statement by statement into machine language is called a/an?
    6·1 answer
  • What can be defined as in information technology environment?
    14·2 answers
  • What is python, the coding language
    6·2 answers
  • Select the phrases that apply to Java classes or methods.
    8·1 answer
  • What is it called when you define a variable for the first time
    12·2 answers
  • The second generation of computer languages is a higher-level language than
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!