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]
3 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]3 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
An ironworker standing 30 feet in the air is safe wearing a full body harness that is not tied off
Nataly_w [17]

Answer

It is FALSE .

Explanation

A full body harness is a  type of safety 'attire' specifically put on for the purposes of protection. Safety harness are necessarily for fall protection. It also provides the user or the worker comfortability and confidence while working on those high risky places. It is advisable that when a worker is exposed to a fall hazard which about six feet and above high to wear a harness that is tied off.

8 0
3 years ago
Read 2 more answers
Ayuda no encuentro la información de estas tres preguntas:
Morgarella [4.7K]

Answer:

Sorry i don't know.........!!!!!!!!!!

Explanation:

3 0
3 years ago
What makes the huns a formidable force for the roman empire?
Maurinko [17]
<span>The Huns were a formidable force to fight. They were able to eat most food without problem which removes the needs for supply trains and such and encourages pillaging. Another reason is that their a cavalry based army which completely decimated roman military since the roman empire consist of flat land and they could outflank, outrun, and could whittle down an army with ease. They also are nomads which means you don't know where they're living and so you can't be on the attack which also gave an advantage. This points that the Huns are a force to be reckon with.</span>
7 0
3 years ago
A customer contacts the help disk stating a laptop does not remain charged for more than 30 minutes and will not charge more tha
fenix001 [56]

Answer:

A. LCD power inverter

B. AC adapter

C. Battery

4 0
3 years ago
(Technical terms) The classification computer into five distinct phases.​
vladimir2022 [97]

Answer:

Computing is any goal-oriented activity requiring, benefiting from, or creating computers. It includes development of both hardware and software. Computing has become a critical, integral component of modern industrial technology. Major computing disciplines include computer engineering, computer science, cybersecurity, data science, information systems, information technology and software engineering

<em>《</em><em>please</em><em> </em><em>mark</em><em> </em><em>as</em><em> </em><em>brainlist</em><em>》</em>

4 0
3 years ago
Other questions:
  • Write an essay on online collaboration, how to do it, the challenges, resolving the challenges, and consider whether the risks a
    12·1 answer
  • Your new home has a vacuum system. what kind of computer is controlling it?
    5·1 answer
  • A short-term job or work project that can be paid or unpaid and can lead to a full-time, paying position is called a(n) _____.
    5·2 answers
  • Which of the following parameters should match in order for a pair of routers to form an adjacency when running OSPFv2? (Points
    9·1 answer
  • A function may return a pointer, but the programmer must ensure that the pointer:
    14·1 answer
  • What happens when you call someone whose phone is off?
    6·2 answers
  • The force required to slide an object is equal to _____.
    13·1 answer
  • HELP PLS
    5·2 answers
  • Does analogue conversation take place in source as transmitter?
    5·2 answers
  • How many ways are used to insert an image from file?koi h kya​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!