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
Energy from sources that can be regenerated or reused is called what?
miskamm [114]

Energy from sources that can be regenerated or reused is called renewable energy.

Renewable energy is energy that can be replenished on a human timescale like hydro-electric power, solar energy and wind power. Geothermal energy is also considered renewable energy.

7 0
3 years ago
When converting text to a table, which feature should be used?
velikii [3]
I’m pretty sure it would be an insert tab
4 0
2 years ago
The 60-watt light bulb has a 400 hour life expectency how much will it cost to operate during its time
expeople1 [14]

Answer:

$2.40

Explanation:

the unit electricity bill is kilo watt hour.

The 60-watt light bulb has a 400 hour life expectency means it will consume

60×400/1000 = 24 KWh units of electricity. Let us suppose each unit of electricity costs is 10 cents.

Then 24×10 = 240 cents  = $2.40

5 0
3 years ago
Write a program that creates a two-dimensional array named height and stores the following data:
antiseptic1488 [7]

Answer:

Explanation:

The following code is written in Java and it simply creates the 2-Dimensional int array with the data provided and then uses the Arrays class to easily print the entire array's data in each layer.

import java.util.Arrays;

class Brainly {

   public static void main(String[] args) {

       int[][] arr = {{16, 17, 14}, {17, 18, 17}, {15, 17, 14}};

   

     

      System.out.print(Arrays./*Remove this because brainly detects as swearword*/deepToString(arr));

   }

}

4 0
2 years ago
Read 2 more answers
Where are parameters such boot order, processor voltage, motherboard raid, hardware virtualization support, and overclocking con
ololo11 [35]

This is configured on the BIOS Setup. During computer start-up usually for windows system this can be accessed via pressing on ESC or Function keys on immediate start up.

6 0
2 years ago
Other questions:
  • What is the main storage device where the computer stores data?
    15·1 answer
  • The Internet shopping cart is an example of which version of the web?
    15·1 answer
  • 5. Drawing Conclusions If you were a person in
    10·1 answer
  • How is a ink pen better than a digital pen.
    8·1 answer
  • Write a function all_cats that consumes a comma-separated string of animals and prints whether all of the animals have "cat" in
    12·1 answer
  • How do you merge on excel?​
    5·1 answer
  • Generally speaking, problems are rarely caused by motherboards. However, there are some instances in which a motherboard can fai
    12·1 answer
  • What is the top 3 cloud provider in the world with statics or data including the example and reason(s).
    11·1 answer
  • When should you stop where you are, drop to the
    11·1 answer
  • Computer science - algorithms - flowcharts
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!