class - Syntax error in Python... I dont understand why -
i'm making program reads numbers , names file , turns them person objects. methods should able display name or number, or peoples' names , numbers. reason i'm getting stuck in environment class syntax error i'm increasing y @ 'y+=2' in while loop inside populate method.
class person (object): pplcnt = 0 def __init__ (self,name,number): print("creating person named ", name, ", phone number: ", number) self.name = name self.number = number person.pplcnt+=1 def getname(self): return self.name def getnum(self): return self.number def getamtppl(self): return person.pplcnt class environtment: x=0 y=0 def __init__(self): self.ppllist = [] def populate(self): people = open("names.txt","r") listof = [] line in people: listof.append(line) x+=1 while y<=x: self.ppllist.append(person(listof[y],listof[y+1]) y+=2 def nameall(self): z=0 while z < int(x/2): print("name: ",self.ppllist[z].getname(),"\nnumber: ",self.ppllist[z].getnum(),"\n")
you're missing parenthesis
self.ppllist.append(person(listof[y],listof[y+1]) 99% of strange syntax errors caused unclosed parenthesis on line above because python trying line continuation makes syntax error. after all, don't expect
self.ppllist.append(person(listof[y],listof[y+1])y+=2 to proper syntax.
Comments
Post a Comment