Nov-05-2017, 12:45 AM
So first and foremost, the problem with your program is a missing
You wrote something like this:
Let's instead create a
.
You wrote something like this:
>>> "Some string: {}"format("spam") File "<stdin>", line 1 "Some string: {}"format("spam") ^ SyntaxError: invalid syntax >>>Note the missing dot.
>>> "Some string: {}".format("spam") 'Some string: spam' >>>More than this though, the reason this error is so hard to see is the length of your lines.
Let's instead create a
__str__
method for your class so we can print it directly. Let's also write the print line a little more sanely:class PassPort(object): def __init__(self, first_name, middle_name, last_name, gender, YOB, iQ): self.species = 'homo-sapien' self.first_name = first_name self.middle_name = middle_name self.last_name = last_name self.gender = gender self.YOB = YOB # (Year of birth) self.iQ = iQ # (Inteligence Quotient) def __str__(self): template = ["The citizen's first name is {first_name}.", "The citizen's middle name is {middle_name}.", "The citizen's last name is {last_name}.", "The species of the citizen is {species}.", "The gender of the citizen is {gender}.", "The citizen was born in the year {YOB}.", "And finally, the citizen has an iQ of {iQ}."] return "\n".join(template).format(**vars(self)) def main(): citizen256032 = PassPort('Jon', 'Ross', 'Dobbs', 'male', 1947, 44) print(citizen256032) if __name__ == "__main__": main()Note now we can now just directly say
print(citizen256032)
.