I am trying to write a class that determines if a person is an adult or not. If a person is an adult then they are 18 or older. And the program should return True. However, I keep getting a return value of False when I implement this program. If anyone has any ideas of what I am doing wrong it would be much appreciated.
class Person:
def __init__(self, name, adult=False, age=0):
self.name = name
self.age = age
self.adult = adult
if self.age >= 18:
self.adult = True
else:
self.adult = False
def birthday(self):
self.age += 1
p = Person("Dan", 17)
p.adult
p.birthday()
p.adult
By my understanding the birthday function should increment the age by 1 when it is called but I do not think it is doing that and I am unsure as to why.