0

Guys, can anyone try to finish this python program?

Homework is: A non-profit organization has announced a collection for charity. The collection is made by calling an audio-text number, and the machine saves the length of each call in seconds to a file. Write a program to find out from the recorded data  number of calls  the total amount collected in euros if the caller contributes 10 cents per second  find out the largest value of the contribution The draft programme is: f = open("mena.txt","r") m = [] for riadok in f: m.append(riadok.strip()) f.close() print(m) vytvorenie dvoch zoznamov - kmena, priezviska / slice def najtext(zoznam): naj = '' return naj print("Najdlhšie krstné meno je", najtext(kmena)) print("Najdlhšie priezvisko je", najtext(priezviska)) zoznam = [] cyklus na spojenie mien a priezvisk a pridanie do zoznamu zoznam.sort() g = open("zoznam_pr_m.txt","w") for i in range(len(zoznam)): print(i+1, ". ", zoznam[i], file = g) g.close()

23rd Mar 2023, 5:47 PM
Matej
Matej - avatar
1 Antwort
+ 1
Your code doesn't seem to be working accordingly to the task requirement. From Google translate I see you wrote about finding longest first name / last name where task required different things. The challenging part is, no example of the record file. There's no clue on how call duration is saved in the file - on each line, or delimited by tab/spaces. This info is necessary to know how to properly process the content read from the file. Read the file, into a `list` <records>, so we can work through it with ease. Assuming the rows are strings, firstly remove unqualified rows (empty and non-numeric rows) After the cleanup, we hsve a valid data. We can now assume length of `list` as number of calls. Define a `list` for storing contribution values - <contributions> Use loop to convert each row in `list` <records> to a number (the call duration - in seconds) Multiply the converted number by 10 (cents) and save it in <contributions> Use sum() to get total contribution Use max() to get highest contribution.
23rd Mar 2023, 10:25 PM
Ipang