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
Does -8 = -21?<br>[this is NOT a trick question]<br>Yes....?<br>No!​
Rudiy27

Answer:

No.

Explanation:

From my knowledge, negative 8 is 8 units to the left of zero, while 21 is 21 units to the left.

This means that they are two different negative numbers! If you see an equation like this, it would be labeled as false.

I'm quite sure I am correct, tell me so if otherwise! :)

#SpreadTheLove

8 0
3 years ago
Read 2 more answers
.) Write a complete C program in one file which takes a double value from the user, cubes it, and prints the result. Your progra
Ket [755]

Answer:

Explanation:

#include <iostream>

using namespace std;

double cube(double);

int main()

{

   double ci=0;

   cout << "Enter avalue :";

   cin >> ci;

   cout << "Cube of " << ci << "is =" << cube(ci) << endl;

   return 0;

}

double cube(double i)

{

   return(i*i*i);

}

8 0
3 years ago
Blender is used by which video game team member?
prohojiy [21]

Answer:

The 2nd one

Explanation:

6 0
3 years ago
Copy the 10 statements as they appear below into your journal.
AURORKA [14]

B A C D C A B B CDAAD

4 0
3 years ago
Read 2 more answers
Carl wants to add two new characters to the extraterrestrial battleship game he's
nikitadnepr [17]

The option that  best explains the game is that a game can have multiple instances using the same class.

<h3>Can a class have multiple instances?</h3>

A game is one that can always create multiple instances of a class. This is known to be the reason that classes are made.

Conclusively,  each object often has its  own specific inner variables and they do not have only if they are static but games of multiple instances is the reason why there is only one class with the new characters.

Learn more about Games from

brainly.com/question/1786465

6 0
2 years ago
Other questions:
  • Select the correct answer.
    15·1 answer
  • This information is generally included on a fax cover sheet.
    15·1 answer
  • When you purchase software in a box, reading the ________ is important to know if the software will function properly?
    13·1 answer
  • In a typical e-mail address, what is the "host"? A. an account designated by a user name. B. the computer that houses an Interne
    7·1 answer
  • A range check that can be used in Microsoft access to calculate the data collected which is date and time
    10·1 answer
  • What code do I have to use in my php if i don’t want my $_SESSION[“variablex”] to destroy? But i already have a session_destroy(
    6·1 answer
  • Complete the sentence.
    5·1 answer
  • The Internet is a worldwide communications network. Which device connects computer networks and computer facilities?
    11·1 answer
  • Darla is going to start writing the HTML code for a web page. What would she start with?
    11·1 answer
  • Calculate the time complexity for the following function in terms of Big O notation. Explain your answer.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!