So, I want to create different objects every time loops run, my object is [name, age, dob] which is appended in an empty list
data = []
I am using class
class PersonsData(object):
# Object constructor
def __init__(self):
print("Person Data")
self.name = ''
self.age = 0
self.doB = 0
# Input Method
def enter_data(self):
size = int(input("Enter the number of data"))
for i in range(size):
self.name = str(input("Enter Your Name" + " ").upper())
try:
self.age = int(input("Enter Your Age" + " "))
except:
print("\n**Enter value in Number**")
self.age = int(input("Enter Your Age" + " "))
self.doB = (input("Enter Your DOB" + " "))
print("\n")
# Display Method
def display(self):
print("Name:", self.name)
print("Age:", self.age)
print("DOB:", self.doB)
the problem is instead of creating new object its just overwritting other, so ho I can create new object
my other half of the code
while True:
print()
print("""
1.Add New Detail
2.Display Detail
3.Quit
""")
choice = int(input("Enter Choice:" + " "))
if choice == 1:
info = PersonsData()
info.enter_data()
print(info.name)
data.append(info)
print(data)
elif choice == 2:
for i in data:
print("--------------------------------")
i.display()
print("--------------------------------")
elif choice == 3:
quit()
else:
print("Invalid choice")
enter_data. It's only setting up that one object