Here's what I've noticed with this code.
First of all your line:
if input = no:
should be changed to
if response == 'no':
I have changed your name "input" to "response" because input is a built-in function in python, and we should not use it as a variable name.
The == operator checks for equivalence of its operands, in this case input and 'no'. The single equals = is the assignment operator in python, meaning that it stores the value on the right side of the = into the name given on the left. For example,
myPetObjects = []
assigns an empty list on the right to the name myPetObjects on the left.
The other change in the code you may notice in the line I rewrote is the quotations added to 'no'. This will compare the value referred to by the name "input" to the string literal 'no'. As previously written, "no" without quotes refers to a name/variable no, which has not been defined and will confuse Python.
Another thing: Since you are using a break statement, which will leave your loop once ran, you can update the while loop line to simply say
while True:
This way, the loop will continue indefinitely until explicitly exited with a "break" statement (which you have included).
As for the actual body of the while loop, it needs a little refactoring. The statement
input("what type of animal")
is a call to the built-in input function of python, and it will evaluate to, or return, a string inputted by the user when prompted with "what type of animal".
So, we can treat it as a string.
With this in mind, let's create your pet objects.
Creating an object in Python has the general syntax
object_name = class_name(parameters)
where parameters refers to the parameters taken by __init__.
This will assign an object instance of your class class_name to object_name by using the assignment operator =.
To append a new object to myPetObjects, we do not need to assign our new object a name. We can instead do:
myPetObjects.append(class_name(parameters))
In your situation, this can be written:
myPetObjects.append(petClass(input("what type of animal"), input("what is its name")))
So, our entire loop:
while True:
myPetObjects.append(petClass(input("what type of animal"), input("what is its name")))
response = input("add another animal?")
if response == 'no':
break
Perhaps a more easily readable version:
while True:
new_pet = petClass(input("what type of animal"), input("what is its name"))
myPetObjects.append(new_pet)
response = input("add another animal?")
if response == 'no':
break
I hope this helps out, and let me know if you have any more questions, if something wasn't clear, or if I didn't answer the question the way you wanted. Good luck!
while Trueif you have a condition to break from it.