-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_classes.py
More file actions
30 lines (22 loc) · 949 Bytes
/
10_classes.py
File metadata and controls
30 lines (22 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Exercise 10 — Classes.
Tutorial: https://pythonbeginner.help/learn/python-classes-and-objects-explained/
TODO:
1. Define a class `Dog` with:
- __init__(self, name) that stores the name
- bark(self) that returns "Woof! I'm <name>."
2. Create a Dog named "Rex" in `rex`, and store its bark() in `sound`.
Run: python exercises/10_classes.py
"""
# --- your code below -------------------------------------------------------
class Dog:
def __init__(self, name):
... # TODO: store the name on self
def bark(self):
... # TODO: return f"Woof! I'm {self.name}."
rex = ... # TODO: Dog("Rex")
sound = ... # TODO: rex.bark()
# --- self-check (don't edit) ----------------------------------------------
assert isinstance(rex, Dog), "rex should be a Dog"
assert rex.name == "Rex", "rex.name should be 'Rex'"
assert sound == "Woof! I'm Rex.", f"sound was {sound!r}"
print("✅ Passed!", sound)