class family:
def __init__(self,name):
self.name=input(f"Enter the {name}s name:") # Entering information for instance variables.
self.surname=input(f"Enter the {name}s surname:")
self.age=int(input(f"Enter the {name}s age:"))
y=input("Does he have wife? (Y/N)") #conditional statements for wife and kids existence.
if y=="Y" or y=="y":
self.wife=input(f"Enter the {name}s wifes name:")
z=input("Does he have any child? (Y/N)")
if z=="Y" or z=="y":
self.kid=True
elif z=="N" or z=="n":
self.kid=None
elif y=="N" or y=="n":
self.wife=None
self.kid=None
# I created three classes for separating persons. This classes inherit family class's codes when you send family class as a parameter.
class grandfather(family): #Grandfathers child is father.
pass
class father(family): #Fathers child is kid
pass
class kid(family):
pass
members=[] # An empty list named members is created to store persons.
while True: #When a person has no wife or kid, The other persons code won't be executed in block of while
grand_father=grandfather("grandfather") # sending "grandfather" etc. strings as parameter to family class.
members.append(grand_father)
if grand_father.wife == None or grand_father.kid == None:
break
elif grand_father.wife != None and grand_father.kid == True:
father_=father("father")
members.append(father_)
if father_.wife == None or father_.kid == None:
break
elif father_.wife != None and father_.kid == True:
kid_=kid("kid")
members.append(kid_)
break
spacebar=0
for x in members: # Output section
print(" " * spacebar +f"Name: {x.name} -- Surname: {x.surname} -- Age: {x.age} -- Wife: {x.wife}")
print("")
spacebar+=5