0
Any tips on OOP?
How can I put if and else method by taking an input and using OOP? Example is like: #can I put an input () in here #if so then class Wolf: def __init__(self, name, color): self.name = name self.color = color def bark(self): print("Grr...") class Dog (Wolf): def bark(self): print("Woof") husky Dog("Max", "grey") husky.bark() #then putting a list in here #and putting an if and else statement that if the input is in the list it will print as the if and else statement should.
2 Respostas
+ 6
Where is that list you want to check against? and what data is contained in the list? dogs' names? and what should be printed when the given input is in the list - or not?
Sorry for a lot of questions, but I'm having difficulties trying to understand your intention.
0
I kinda want to put like
#choose one to input
#steal or walk
choosen_one = input ()
class Animal:
def __init__(self, name, color):
self.name = name
self.color = color
def bark(self):
print ("Grrrrr...")
class Dog (Animal):
def bark (self):
print ("Woof!")
husky Dog("Max", "grey")
husky.bark()
#then a list in here of steal and walk.
#then an if statement that if the player input walk it will output the name of the dog only. And if they input steal the dog will only bark