Any tips on OOP? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

10th Oct 2022, 12:33 PM
Iamno0v
Iamno0v - avatar
2 Answers
+ 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.
10th Oct 2022, 1:04 PM
Ipang
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
10th Oct 2022, 9:28 PM
Iamno0v
Iamno0v - avatar