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
Task 5: Create the GET_CREDIT_LIMIT procedure to obtain the full name and credit limit of the customer whose ID currently is sto
lidiya [134]

The SQL statement that would create the GET_CREDIT_LIMIT procedure to obtain the full name and credit limit of the customer is:

GET_CREDIT_LIMIT

SELECT CUST_ID 125

FROM FIRST_NAME, LAST_NAME, CREDIT_LIMIT

WHERE LAST_NAME ="Smith"

<h3>What is SQL?</h3>

This is an acronym that means Structured Query Language that is used in handling data in a database.

Hence, we can see that from the attached image, there is a table that contains the details of customers and their various data such as their first and last names, credit limits, address, etc, and the  GET_CREDIT_LIMIT procedure is shown above.

Read more about SQL here:

brainly.com/question/25694408

#SPJ1

3 0
1 year ago
This is gonna be very long but I have no idea what to do, I'm confused.
kaheart [24]

for such experiment, you do it with care and to acquire and determine to put experience in it

Explanation:

because without you been or using experience the experiment will not correct

8 0
2 years ago
 In which part of a professional email should you try to be brief, but highly descriptive? 
quester [9]
The subject line should be a brief message explaining some of the contents of the email.
4 0
3 years ago
Does a call go through on the first ring when hanging up on a house phone
Alinara [238K]
I don't think so, it doesn't on my home phone.
6 0
3 years ago
This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balance
aleksandr82 [10.1K]

Answer:

Question Options :

(1) Prompt the user to input five pairs of numbers: A player’s jersey number (0 – 99) and the player’s rating (1 – 9). Store the jersey numbers in one int array and the ratings in another int array. Output these array(i.e., output the roster).

(2) Implement a menu of options for a user to modify the roster. Each option is represented by a single character. The program initially outputs the menu, and outputs the menu after a user chooses an option. The program ends when the user chooses the option to Quit. For this step, the other options do nothing. (2 pt)

(3) Implement the “Output roster” menu option. (1 pt)

(4) Implement the “Add player” menu option. Prompt the user for a new player’s jersey number and rating. Append the values to the two arrays. (1 pt)

(5) Implement the “Delete player” menu option. Prompt the user for a player’s jersey number. Remove the player from the roster (delete the jersey number and rating). (2 pts)

(6) Implement the “Update player rating” menu option. Prompt the user for a player’s jersey number. Prompt again for a new rating for the player, and then change that player’s rating. (1 pt)

(7) Implement the “Output players above a rating” menu option. Prompt the user for a rating. Print the jersey number and rating for all players with ratings above the entered value. (2 pts)

/******************************************************************************

This program will store roster and rating information for a soccer team.

                             

*******************************************************************************/

#include <iostream>

#include <vector>

using namespace std;

int main() {

   vector< int> jerseyNumber;

   vector< int> rating;

   int temp;

   for (int i = 1; i <= 5; i++) {

       cout << "\nEnter player " << i << "'s jersey number: ";

       cin >> temp;

       if ((temp >= 0) && (temp <= 99)){

           jerseyNumber.push_back(temp);}

       cout << "Enter player " << i << "'s rating: ";

       cin >> temp;

       if ((temp >= 0) && (temp <= 9)){

       rating.push_back(temp);}

       cout << endl;

   } cout << endl;

   cout << "ROSTER" << endl;

   for (int i = 0; i < 5; i++)

cout << "Player " << i + 1 << " -- " << "Jersey number: " << jerseyNumber.at(i) << ", Rating: " << rating.at(i) << endl;

   char option;

   while (true) {

       cout << endl;

       cout << "MENU" << endl;

       cout << "a - Add player" << endl;

       cout << "d - Remove player" << endl;

       cout << "u - Update player rating" << endl;

       cout << "r - Output players above a rating" << endl;

       cout << "o - Output roster" << endl;

       cout << "q - Quit" << endl << endl;

       cout << "Choose an option: " << endl;

       cin >> option;

       switch (option) {

           case 'a':

           case 'A':

               cout << "Enter another player's jersey number: " << endl;

               cin >> temp;

               if ((temp >= 0) && (temp <= 99)){

                   jerseyNumber.push_back(temp);}

               cout << "Enter another player's rating: " << endl;

               cin >> temp;

               if ((temp >= 0) && (temp <= 9)){

                   rating.push_back(temp);}

               break;

           case 'd':

           case 'D':

               cout << "Enter a jersey number: ";

               cin >> temp;

               for (int i = 0; i < jerseyNumber.size(); i++) {

                   if (jerseyNumber.at(i) == temp) {

                       jerseyNumber.erase(jerseyNumber.begin() + i);

                       rating.erase(rating.begin() + i);

                       break; }

               } break;

           case 'u':

           case 'U':

               cout << "Enter a jersey number: ";

               cin >> temp;

               for (int i = 0; i < jerseyNumber.size(); i++) {

                   if (jerseyNumber.at(i) == temp) {

                       cout << "Enter a new rating " << "for player: ";

                       cin >> temp;

                       rating.at(i) = temp;

                       break; }

               } break;

           case 'r':

           case 'R':

               cout << "Enter a rating: ";

               cin >> temp;

               cout << "\nABOVE " << temp << endl;

               for (int i = 0; i < jerseyNumber.size(); i++)

                   if (rating.at(i) > temp)

               cout << "Player " << i + 1 << " -- " << "Jersey number: " << jerseyNumber.at(i)

               << ", Rating: " << rating.at(i) << endl;

               break;

           case 'o':

           case 'O':

               cout << "ROSTER" << endl;

               for (int i = 0; i < jerseyNumber.size(); i++)

               cout << "Player " << i + 1 << " -- " << "Jersey number: " << jerseyNumber.at(i)

               << ", Rating: " << rating.at(i) << endl;

               break;

           case 'q':

               return 0;

               default: cout << "Invalid menu option." << " Try again." << endl;

       }

     }

   }

Explanation:

6 0
3 years ago
Other questions:
  • Disk scheduling algorithms in operating systems consider only seek distances, because Select one: a. modern disks do not disclos
    13·1 answer
  • Drag each storage device to its category.
    7·1 answer
  • A hard drive cannot be partitioned until the device _________ is set.
    5·2 answers
  • Given an array A of size N, and a number K. Task is to find out if it is possible to partition the array A into K contiguous sub
    9·1 answer
  • Computer is created by aliens?!
    14·1 answer
  • One advantage of using a security management firm for security monitoring is that it has a high level of expertise.
    15·2 answers
  • (Display four patterns using loops) Ask the user to enter an integer to
    8·1 answer
  • Not every organization integrates with the Internet, but all use some or most of the technology that gave rise to it.
    15·1 answer
  • Which properties would be useful to know to search for a Word document? Check all that apply.
    7·1 answer
  • It is important to consider design details when creating an api because: ______________
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!