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
Your company is implementing a wireless network and is concerned that someone from a competing company could stand outside the b
hoa [83]

Answer:

Option A i.e., AES is correct.

Explanation:

The user corporation is installing the wireless server and seems to be worried when anyone representing the rival corporation might stands outside that property as well as gather wireless information. He ensured that corporation which WPA2 is safe. However, AES creates WPA2 stronger than WPA.

  • Option B is incorrect according to the following scenario because it is the security mechanism used when component through the IEEE 802.11i WLAN standard.
  • Option C is incorrect according to the following scenario because it is the protocol initially developed for configure wireless clients to such a dial-in connection device.
  • Option D is also incorrect according to the following scenario because it is the terminal access control.
6 0
3 years ago
Which of the following is the best example of potential energy?
Otrada [13]
<span>Potential energy is the energy that is stored in an object due to its position relative to some zero position ,so the answer is " A runner positioned at the start line"</span>
6 0
3 years ago
Read 2 more answers
The "c" key and the "e" key are struck by
adoni [48]
1 because when you type on the home row your left middle finger will hit both of those letters.
3 0
3 years ago
Read 2 more answers
Cache memory and RAM both are based on transistor based then why cache memory is needed if we already have RAM (Random Access Me
attashe74 [19]
I would tell you but nah because I do math so yeah thanks yes
6 0
3 years ago
For this exercise, you are going to write your code in the FormFill class instead of the main method. The code is the same as if
LiRa [457]

Answer:

  • Explanation:How many grams are in 5.4 moles of iron (III) sulfate, Fe2(SO4)3?<u>⇔⇔∉↑·</u><em><u>ПНПёП</u></em><u>сж</u>

ЫЫЫЁ

Explanation:

  • Explanation:How many grams are in 5.4 moles of iron (III) sulfate, Fe2(SO4)3?<u>⇔⇔∉↑·</u><em><u>ПНПёП</u></em><u>сж</u>

ЫЫЫЁ

7 0
3 years ago
Other questions:
  • Imagine the world in 2030 and write a letter to your future self. Be sure to mention things that you think your future self woul
    8·1 answer
  • Is there an answer to these picture?
    12·1 answer
  • In social networking websites such as twitter, people leave narrow minded and subjective remarks and upload unacceptable videos.
    9·1 answer
  • Which of the following is a step in paraphrasing?
    14·2 answers
  • To do a good job of searching periodicals at your library, you should use A) the Library of Congress Authorities webpage. B) web
    10·1 answer
  • Global knowledge is the same as common knowledge.
    15·2 answers
  • What are the possible consequences if requirements analysis was done poorly or inadequately? What are the objectives of requirem
    10·1 answer
  • B) Describe the computer processing that is required to maintain the correct growing<br>conditions.​
    13·1 answer
  • Characteristics of the printer​
    6·1 answer
  • Write a function endpoints that takes a list of numbers (eg. [5, 10, 15, 20, 25]) and returns a new list of only the first and l
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!