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
select three types of school which specifically emphasize learning through creativity, self expression, and play
sattari [20]

The first thing that comes to mind is preschool. Then kindergarden. Another one would probably be a daycare center, but I'm not sure that qualifies as a school.

4 0
4 years ago
Read 2 more answers
Two organizations cannot have the same name for a computer true or false
liberstina [14]
The answer is False.  Two organizations can have the same name for a computer.  <span>Both </span>computers may<span> have the </span>same name<span>, are on the </span>same<span> subnet, and are on the </span>same domain<span>. But each </span>computer<span> has a unique IP address.</span>
4 0
3 years ago
a user's given name followed by the user's age from standard input. Then use an ofstream object named outdata (which you must de
RUDIKE [14]

Answer:

See explaination for program code

Explanation:

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

int main() {

string name;

int age;

cout << "Enter name of user: ";

getline(cin, name);

cout << "Enter age of user: ";

cin >> age;

ofstream outdata("outdata");

outdata << name << " " << age << endl;

outdata.close();

return 0;

}

4 0
3 years ago
Computer forensics is practiced _____. A. Only by specially trained government and law-enforcement personnel B. By many organiza
laiz [17]

Answer:

Option B is the correct answer.

<h3>Computer forensics is practiced by many organizations, including public- and private-sector organizations such as hospitals, law enforcement, and businesses. </h3><h3 />

Explanation:

Computer forensics can be defined as a branch of digital forensics that deals with the evidences and and proofs found on all digital storage media such as computers.

It is basically a step for enhancing security bases of communication. Therefore it is mainly used by law-enforcement personnel but it can also be practiced by other institutions for the purpose of self security.

<h3>I hope it will help you!</h3>
4 0
3 years ago
Theresa is a certified teacher. She just had a baby and would like to stay home, but still wants to teach. Which career would be
vesna_86 [32]
I think it will be online classes (B.)
8 0
3 years ago
Read 2 more answers
Other questions:
  • What enables computers to run multiple operating systems and multiple software applications at the same time and creates multipl
    6·1 answer
  • On the Internet, you can use a(n)______to look for information on any topic, such as books, movies, scholarly articles, news, an
    6·2 answers
  • How to transfer photos from iphone to iphone?
    14·2 answers
  • Objects of the calculator class require no additional information when created. define an object named calc, of type calculator.
    14·2 answers
  • Why is operating system pivotal in teaching and learning
    11·1 answer
  • What can provides access to the only menu in office 2007​
    13·1 answer
  • A buffer is filled over a single input channel and emptied by a single channel with a capacity of 64 kbps. Measurements are take
    11·1 answer
  • Identify the programming language released by
    10·1 answer
  • Write a program, using case statements, that mimics a calculator. The program should take as input two integers and the operatio
    9·1 answer
  • ___________________ describes the process of combining voice, video, and data communications over a common network infrastructur
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!