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
Arturiano [62]
2 years ago
14

This is similar to the last problem, except that the first number on a line is an ID number that identifies an account. The same

ID number may appear on any number of lines. Use a Dictionary to accumulate, for each ID, the sum of all the numbers that are on all the lines with that ID number. Call the input file id_data.txt. Write an output file called ID_sums.txt. On each line of the output fille, print an ID number and the sum. Sort the lines by the numerical order of the IDs
Computers and Technology
1 answer:
andre [41]2 years ago
6 0

Answer:

Following are the code to this question:

def getSum(ID):#defining a method getSum that accept an ID

   t= 0#defining a variable t

   while ID!= 0:#defining while loop to check ID not equal to 0

       t+= ID % 10# holding remainder value

       ID = ID // 10#holding quotient value

   return t#return total value

def readRecord(S):#defining a method readRecord that hold list  

   f_Read = open("idInfo.txt","r")#defining a variable f_Read to open file

   for C_ID in f_Read:#defining for loop to hold file value  

       C_ID = C_ID.replace('\n', '')#use replace method

       S[C_ID] = getSum(int(C_ID))#use list to method value

   f_Read.close()#close file

def sortRecord(ID_List, t_List):#defining a sortRecord

   for x in range(len(ID_List) - 1):#defining for loop to calculate the length of list  

       for y in range(0, len(ID_List) - x - 1):#defining for loop to calculate the length of list

           if ID_List[y] > ID_List[y+1]:#defining if block to check value is greater

               ID_List[y], ID_List[y+1] = ID_List[y+1], ID_List[y]#swap the value

               t_List[y], t_List[y+1] = t_List[y+1], t_List[y]#swap the value

def showReport(ID, t):#defining a method showReport that accept id and t

   for i in range(len(ID)):#defining for loop to hold index value

       print(ID[i]," ",t[i])#print index value

def writeRecord(ID_List, t_List):#defining a method writeRecord that accept two list

   f_Write = open("idSorted.txt","w")#defining a variable f_Write to hold store value in file

   for i in range(len(ID_List)):#defining a for loop to store value with index

       f_Write.write(ID_List[i])#hold list value

       f_Write.write(" ")    #for space

       f_Write.write(str(t_List[i]) + "\n")# add index value

   f_Write.close()#close file

def run():#defining method run

   S = {}#defining an empty list

   readRecord(S)#passing list into readRecord method

   ID_List = list(S.keys())#defining a variable that holds key value in list

   t_List = list(S.values())#defining a variable that holds values value in list

   sortRecord(ID_List, t_List)#calling a method sortRecord by passing value

   showReport(ID_List, t_List)#calling a method showReport by passing value

   writeRecord(ID_List, t_List)#calling a method writeRecord by passing value

if "run":

   run()

Output:

Please find the attached file.

Explanation:

In the above program code, 6 method getSum, readRecord, sortRecord,showReport, writeRecord, and run method is defined, in which getSum and readRecord is used a single list store value in parameters, and in other methods, it accepts two parameter to store value in key and values form and use a txt file to store and take value.    

In the run method, an empty list s is declared, that pass into the variable ID_List and t_List, and call the method, in this program two a text file "idInfo.txt" is used, that holds some value in the file, and create another file that is "idSorted.txt", in this file it stores the value in the numerical order of the ID's.

You might be interested in
You are the security administrator for your company. You have been informed by human resources that one of the employees in acco
andreyandreev [35.5K]

Answer:

The answer is "option d".

Explanation:

When an employee is fired so, their account should be closed, and the employee records should be maintained over a certain time specified by the rules and procedures of the company. and other options can be defined as:

  • In option a,  It is not important to delete the user account because later on, the company would need info about that account.
  • In option b, There's no need to talk to the superior of the employer.
  • In option c,  change the user password is not enough to update the user's password; the account should also be deleted.
5 0
3 years ago
What mistake do you think you might make related to changing the data in a cell that's used in a formula?
Virty [35]

Answer

Hi,

The mistake could be the #DIV/0! error , or a #REF! error

Explanation

When changing the data in a cell that’s used in a formula, a #DIV/0! Error can occur when the formula attempts to divide a number by 0 or an empty cell. To rectify this, you will need to change the value of that cell to a value not equal to 0. In some cases, the #REF! error could be displayed. This means that the formula refers to a cell that is not valid.

Hope this Helps!

4 0
3 years ago
Directions: Asba student of Contact Center Service, you already have an experience using different computer programs. Try to rem
ELEN [110]

Explanation:

can u suggest a title about quarantine

ex: My quarantine life

8 0
3 years ago
Read 2 more answers
The laws governing search and seizure in the public sector are much more straightforward than those in the private sector. TRUE
Lapatulllka [165]

Answer:

True

Explanation:

Because of the contract that you have agreed to when joining the work force. Which is different from the private sector.

7 0
3 years ago
Suppose data is available for an on-line music distributor. This data includes: song title, artist performing the song, date son
garri49 [273]

Answer:

The answer is "Option a".

Explanation:

In this question, the only choice "a" is correct because in the question it is declared that it includes: your track title, the performance artist, the date their track is bought, the fee for the track. Its number of music purchased by a given artist on a particular date is based only on details available on the distributor's song title, performing, date purchased, the sum paid.

5 0
3 years ago
Other questions:
  • WordArt styles allow you to add ____.
    9·1 answer
  • Select all that apply.
    8·2 answers
  • You should use html elements instead of server controls when
    11·1 answer
  • Renee's creating a plan for her business's information system. What should she do after she determines the goals for her busines
    10·1 answer
  • What is it called when two different files generate the same hashing result?
    15·1 answer
  • Probability can be used to determine the likelihood of specific __________
    6·2 answers
  • True or false? Compared to verbal language a shot is like a word
    12·1 answer
  • Pls help. will give brainliest to FIRST and CORRECT answer!
    14·1 answer
  • Please help!!! I am very confused about this question!
    10·1 answer
  • Do you think privacy policies are effective in social networking sites?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!