0

I'm solving a problem described in English and because I didn't learn to code in English, it's difficult for me to understand what the guide want me to do. I'll be appreciated if anyone would like to explain for me.

The full question is here. My question is if the list maintained in the question is the LIST in Python. If so, the created class seems useless. How can I use the overridden ==?(literally I don't know which two should be compared in this case) I don't know what to do next.

Here's what I've done.


    def __init__(self,fn,ln,num):
        self.firstName=fn
        self.lastName=ln
        self.idnumber= num

        
    def insert(self):
        newfirstname=input('First Name: ')
        newlastname=input('Last Name: ')
        newidnumber=input('ID Number: ')
        personnew=Person(newfirstname,newlastname,newidnumber)
        persons.append(personnew)
    # def __eq__():    
    # def __greater__():    
    # def str():
        
        


filepath=input('the path of the file is:')
n=input('how many lines are required:')
n=int(n)

persons=[]
f=open(filepath,'r')

for i in range(n):
    print(f.readline())
    person=Person(f.readline().split()[0],f.readline().split()[1],f.readline().split()[2])
    persons.append(person)

When I input n=2, the output is not the first and the second line.

Looking forward to someone to help and thank you in advance.

Jingran
  • 1
  • 1
  • What is your output? You should get the first line but not the second, since you use `f.readline()` several times without printing anything – TUI lover Mar 12 '21 at 14:46
  • Your loop should look like this `for i in range(n):` `strLine=f.readline()` `print(a)` `wordsline=a.split()` `person=Person(wordsline[0], wordsline[1], wordsline[2])` `persons.append(person)` – TUI lover Mar 12 '21 at 15:03
  • Your problem is unwell defined, so you can only assume that the persons should be sorted based on their ID's – TUI lover Mar 12 '21 at 15:07

0 Answers0