-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathnode.py
More file actions
32 lines (22 loc) · 973 Bytes
/
node.py
File metadata and controls
32 lines (22 loc) · 973 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
31
32
# Create here the Node Class
# class Node:
# pass
class Node:
id: int
parent: int
def __init__(self, id: int, parent: int):
if not isinstance(id, int) or not isinstance(parent, int):
#validação dupla de instancia para id e parent.
raise ValueError("Node class init raises given non integer.")
if parent > id:
# validação se o parent é maior que o id.
# OBS poderia ser usado o >= para validar se é maior ou iqual,
# mas foi optado separar as validações por motivos didaticos
raise ValueError("Node does not accept PARENT greater than children.")
if parent == id:
# validação se o parent é iqual ao id.
raise ValueError("Node does not accept ID as PARENT of itself.")
self.id = id
self.parent = parent
def __repr__(self):
return f"Node({self.id}, {self.parent})"