Apr-24-2023, 06:05 PM
(This post was last modified: Apr-24-2023, 06:06 PM by deanhystad.)
Other question, I try to make a sub classes and when there is no argument then value 0
But get the following error
But get the following error
from datetime import datetime, date class persoon: def __init__(self, naam, sekse, geboortedatum): self.naam = naam self.sekse = sekse self.geboortedatum = datetime.strptime(geboortedatum, '%d-%m-%Y').date() def getNaam(self): return self.naam def getGebDatum(self): return self.geboortedatum def isVrouw(self): if self.sekse == "V": return True else: return False def isMan(self): if self.sekse == "M": return True else: return False def leeftijd(self): today = date.today() age = (today.year - self.geboortedatum.year) return age class Docent(persoon): def __init__(self, naam, sekse, geboortedatum,*Salaris): if(Salaris==None): self.Salaris = "0" else: self.Salaris = Salaris d1 = Docent("John", "M", "24-04-2000") print(d1.naam)
Error:3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)]
Python Type "help", "copyright", "credits" or "license" for more information.
[evaluate Objectgeoriënteerd programmeren_FeedackVraag4.py]
Traceback (most recent call last):
File "C:\Python\Objectgeoriënteerd programmeren_FeedackVraag4.py", line 43, in <module>
print(d1.naam)
builtins.AttributeError: 'Docent' object has no attribute 'naam'
deanhystad write Apr-24-2023, 06:06 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.