Your First Class
Completed
Create a class Dog with attributes name and age set in __init__, and a method bark() returning NAME says woof!. Read a name and age, create a dog, print bark() and then the age in dog years (age × 7).
Input
Two lines: name, age.
Output
Two lines.
Example
Input
Rex 3
Output
Rex says woof! 21
Editor
Python
Hints
__init__ runs when you create an object.
self refers to the object the method is called on.
Solution explanation
A class is a blueprint; each object (instance) has its own attribute values.
Show solution
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
def bark(self):
return f"{self.name} says woof!"
dog = Dog(input(), int(input()))
print(dog.bark())
print(dog.age * 7)