Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CSCI30_Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Adrian Cansino
CSCI30_Project
Commits
f3cbf0dd
Commit
f3cbf0dd
authored
Dec 08, 2019
by
Marc Yap
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace family_tree.py
parent
b6b4a537
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
family_tree.py
family_tree.py
+58
-0
No files found.
family_tree.py
View file @
f3cbf0dd
...
@@ -333,6 +333,52 @@ class Person:
...
@@ -333,6 +333,52 @@ class Person:
"""Return the name."""
"""Return the name."""
return
self
.
name
return
self
.
name
def
openfile
(
filename
):
#Open Method
atree
=
FamilyTree
()
fname
=
filename
+
".ft"
readF
=
open
(
fname
,
"r"
)
familyname
=
readF
.
readline
()
.
split
()[
1
]
count
=
int
(
readF
.
readline
()
.
split
()[
1
])
for
i
in
range
(
count
):
name
=
readF
.
readline
()
.
split
()[
1
]
age
=
int
(
readF
.
readline
()
.
split
()[
1
])
sex
=
bool
(
readF
.
readline
()
.
split
()[
1
])
person
=
Person
(
name
,
age
,
sex
)
atree
.
insert_person
(
person
)
links
=
int
(
readF
.
readline
()
.
split
()[
1
])
for
i
in
range
(
links
):
line
=
readF
.
readline
()
.
split
()
p1
=
atree
.
get_person
(
line
[
1
])
p2
=
atree
.
get_person
(
line
[
2
])
p2
.
set_parent
(
p1
)
readF
.
close
()
return
atree
def
savefile
(
filename
,
tree
):
#Save Method
fname
=
filename
+
".ft"
saveF
=
open
(
fname
,
"w+"
)
saveF
.
write
(
"family "
+
filename
+
"
\n
"
)
count
=
len
(
tree
.
family_tree
)
saveF
.
write
(
"count "
+
str
(
count
)
+
"
\n
"
)
for
i
,
x
in
tree
.
family_tree
.
items
():
name
=
x
.
get_name
()
age
=
str
(
x
.
get_age
())
sex
=
str
(
x
.
get_sex
())
saveF
.
write
(
"name "
+
name
+
"
\n
"
)
saveF
.
write
(
"age "
+
age
+
"
\n
"
)
saveF
.
write
(
"sex "
+
sex
+
"
\n
"
)
links
=
count
-
1
saveF
.
write
(
"links "
+
str
(
links
)
+
"
\n
"
)
for
i
,
x
in
tree
.
family_tree
.
items
():
if
x
is
not
tree
.
root
:
parent
=
x
.
get_parent
()
saveF
.
write
(
"child "
+
parent
.
get_name
()
+
" "
+
x
.
get_name
()
+
"
\n
"
)
def
main
():
def
main
():
r"""For testing.
r"""For testing.
...
@@ -381,6 +427,18 @@ def main():
...
@@ -381,6 +427,18 @@ def main():
print
(
"relationship {} is {}'s: {}"
.
format
(
D
,
C
,
ftree
.
relationship
(
C
,
D
)))
print
(
"relationship {} is {}'s: {}"
.
format
(
D
,
C
,
ftree
.
relationship
(
C
,
D
)))
print
(
"relationship {} is {}'s: {}"
.
format
(
C
,
D
,
ftree
.
relationship
(
D
,
C
)))
print
(
"relationship {} is {}'s: {}"
.
format
(
C
,
D
,
ftree
.
relationship
(
D
,
C
)))
print
(
""
)
#test for opening and saving files
ntree
=
openfile
(
"chandelier"
)
ntree
.
find_root
()
ntree
.
precompute
()
print
(
"The root of the tree is {}."
.
format
(
ntree
.
root
))
for
key
,
node
in
ntree
.
family_tree
.
items
():
print
(
"{}: {}"
.
format
(
node
,
node
.
get_generation
()))
savefile
(
"test"
,
ntree
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
main
()
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment