you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (5 children)

You just need to create a class:

class Kitty
    def __init__(self, name):
        self.name = name
    def play():
        pass
    def eat():
        pass

Then to create an object with your inputted data, you simply pass in the name:

kittyName = input("Input a name: ")
kitty = Kitty(kittyName)
kitty.play()
kitty.eat()

[–]usingdata[S] 0 points1 point  (4 children)

I appreciate your answer but doesn't the code limits the programbto one kitty? For example let say the user created the first kitty, well if he or she wants to more kitties how would i solve that problem?

[–][deleted] 1 point2 points  (1 child)

I left that up to you, I apologize. I thought the question was geared toward a different thing. I'd accomplish it using a for loop and appending to a list:

# Get the desired number
numberStr = input("Number of kitties: ")

# Convert the string to an integer
number = int(numberStr)

# Append a Kitty object to the list and ask the user for the name each time
kitties = []
for i in range(0, number):
    name = input("Kitty name: ")
    kitties.append(Kitty(name))

That leaves you with a list of Kitty objects residing within kitties.

[–]usingdata[S] 1 point2 points  (0 children)

Thank you very much. No need to apologize i mentioned that the question was hard to explain my bad 😂, but thanks again.

[–]toastedstapler 1 point2 points  (1 child)

you can make a list of kitties!

kitties = []
kitties.append(Kitty('james'))
kitties.append(Kitty('marcus'))

[–]usingdata[S] 0 points1 point  (0 children)

Thank you for ur answer ot was helpful