Might I suggest a solution to not using lists:
Given that your class has structure :
class Animal:
def __init__(self,name,alter,typ):
self.typ = typ
self.name = name
self.alter = alter
In your main code, you can make some changes so that you don't need to use lists, i.e. change the class to :
class Animal:
def __init__(self):
self.typ = None
self.name = None
self.alter = None
This will basically allow you to declare a class object without having to set its attributes when declaring it.
So, with the changes made in the class structure, your main code, i.e. this code:
count = int(input("Enter amount of Inputs: "))
try:
while count>0:
wuff = Animal(input("Enter Name: "), input("Enter Age: "), input("Enter Type: "))
wuff = "object" + count
count-=1
except ValueError:
print("Wrong input!")
print(wuff.name, wuff.alter, wuff.typ)
We can change this to the following code:
count = int(input("Enter amount of Inputs: "))
wuff = Animal()
try:
while count > 0:
wuff.name = str(input("Enter Name: "))
wuff.alter = int(input("Enter Age: ")) # assuming that you mean to set age by the attr. alter
wuff.typ = str(input("Enter Type: "))
# wuff = "object" + count # removed the line because it is incorrect
# The code line was removed tries to add a string literal with an integer.
count -= 1
except ValueError:
print("Wrong input!")
print(wuff.name, wuff.alter, wuff.typ)
In order to create multiple objects, you need to have multiple identifiers.
So you need to use some form of storing method, i.e. some sort of List or dictionary. So to do this :
class Animal:
def __init__(self,name,alter,typ):
self.typ = typ
self.name = name
self.alter = alter
count = int(input("Enter amount of Inputs: "))
objectDict = {}
try:
while count > 0:
Name = str(input("Enter Name: "))
Alter = int(input("Enter Age: "))
Typ = str(input("Enter Type: "))
objectDict[Name] = Animal(Name, Alter, Typ)
count -= 1
except ValueError:
print("Wrong input!")
print(wuff.name, wuff.alter, wuff.typ)
I hope this was useful.
You can avoid lists (although not recommended) and stuff by storing the objects by using a SQL DB and storing the objects in the form of tables of attributes and stuff.
I hope this answer was satisfactory.