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
Temujin
CSCI30_Project
Commits
9b822ba9
Commit
9b822ba9
authored
Dec 10, 2019
by
Temujin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://gitlab.discs.ateneo.edu/Omanko6969/csci30_project
parents
325adb33
0b442d74
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
2 deletions
+91
-2
family_tree.py
family_tree.py
+91
-2
No files found.
family_tree.py
View file @
9b822ba9
...
@@ -212,7 +212,7 @@ class FamilyTree:
...
@@ -212,7 +212,7 @@ class FamilyTree:
"""Return the index in the times table."""
"""Return the index in the times table."""
return
self
.
times
[
n
]
return
self
.
times
[
n
]
def
great
(
self
,
n
):
def
GREAT
(
self
,
n
):
"""Return a string of n 'greats' separated by '-' ."""
"""Return a string of n 'greats' separated by '-' ."""
return
"-"
.
join
([
"great"
]
*
n
)
return
"-"
.
join
([
"great"
]
*
n
)
...
@@ -338,7 +338,10 @@ def openfile(filename): #Open Method
...
@@ -338,7 +338,10 @@ def openfile(filename): #Open Method
for
i
in
range
(
count
):
for
i
in
range
(
count
):
name
=
readF
.
readline
()
.
split
()[
1
]
name
=
readF
.
readline
()
.
split
()[
1
]
age
=
int
(
readF
.
readline
()
.
split
()[
1
])
age
=
int
(
readF
.
readline
()
.
split
()[
1
])
sex
=
bool
(
readF
.
readline
()
.
split
()[
1
])
if
readF
.
readline
()
.
split
()[
1
]
==
"true"
:
sex
=
True
else
:
sex
=
False
person
=
Person
(
name
,
age
,
sex
)
person
=
Person
(
name
,
age
,
sex
)
atree
.
insert_person
(
person
)
atree
.
insert_person
(
person
)
...
@@ -350,6 +353,7 @@ def openfile(filename): #Open Method
...
@@ -350,6 +353,7 @@ def openfile(filename): #Open Method
p2
.
set_parent
(
p1
)
p2
.
set_parent
(
p1
)
readF
.
close
()
readF
.
close
()
atree
.
precompute
()
return
atree
return
atree
def
savefile
(
filename
,
tree
):
#Save Method
def
savefile
(
filename
,
tree
):
#Save Method
...
@@ -375,6 +379,91 @@ def savefile(filename, tree): #Save Method
...
@@ -375,6 +379,91 @@ def savefile(filename, tree): #Save Method
parent
=
x
.
get_parent
()
parent
=
x
.
get_parent
()
saveF
.
write
(
"child "
+
parent
.
get_name
()
+
" "
+
x
.
get_name
()
+
"
\n
"
)
saveF
.
write
(
"child "
+
parent
.
get_name
()
+
" "
+
x
.
get_name
()
+
"
\n
"
)
def
commandLine
():
tree
=
FamilyTree
()
while
True
:
cmd
=
input
()
.
split
()
if
cmd
[
0
]
==
"count"
:
print
(
len
(
tree
.
family_tree
.
items
()))
elif
cmd
[
0
]
==
"age"
:
try
:
print
(
tree
.
get_person
(
cmd
[
1
])
.
get_age
())
except
KeyError
:
print
(
"Error: no such person "
+
cmd
[
1
])
elif
cmd
[
0
]
==
"sex"
:
try
:
if
tree
.
get_person
(
cmd
[
1
])
.
get_sex
():
print
(
"male"
)
else
:
print
(
"female"
)
except
KeyError
:
print
(
"Error: no such person "
+
cmd
[
1
])
elif
cmd
[
0
]
==
"ancestors"
:
try
:
if
len
(
tree
.
get_ancestors
(
cmd
[
1
]))
==
0
:
print
(
"(no ancestors)"
)
else
:
for
person
in
tree
.
get_ancestors
(
cmd
[
1
]):
print
(
person
)
except
KeyError
:
print
(
"Error: no such person "
+
cmd
[
1
])
elif
cmd
[
0
]
==
"descendants"
:
try
:
if
len
(
tree
.
get_descendants
(
cmd
[
1
]))
==
0
:
print
(
"(no descendants)"
)
else
:
for
person
in
tree
.
get_descendants
(
cmd
[
1
]):
print
(
person
)
except
KeyError
:
print
(
"Error: no such person "
+
cmd
[
1
])
elif
cmd
[
0
]
==
"edit-name"
:
try
:
if
tree
.
family_tree
.
get
(
cmd
[
2
])
==
None
:
tree
.
get_person
(
cmd
[
1
])
.
set_name
(
cmd
[
2
])
tree
.
family_tree
[
cmd
[
2
]]
=
tree
.
family_tree
[
cmd
[
1
]]
del
tree
.
family_tree
[
cmd
[
1
]]
else
:
print
(
"Error: "
+
cmd
[
2
]
+
" exists already"
)
except
KeyError
:
print
(
"Error: no such person "
+
cmd
[
1
])
elif
cmd
[
0
]
==
"edit-age"
:
try
:
tree
.
get_person
(
cmd
[
1
])
.
set_age
(
cmd
[
2
])
except
KeyError
:
print
(
"Error: no such person "
+
cmd
[
1
])
elif
cmd
[
0
]
==
"edit-sex"
:
try
:
if
cmd
[
2
]
==
"true"
:
tree
.
get_person
(
cmd
[
1
])
.
set_sex
(
True
)
else
:
tree
.
get_person
(
cmd
[
1
])
.
set_sex
(
False
)
except
KeyError
:
print
(
"Error: no such person "
+
cmd
[
1
])
elif
cmd
[
0
]
==
"relationship"
:
try
:
if
cmd
[
1
]
==
cmd
[
2
]:
print
(
"Error: inputs must be distinct"
)
else
:
print
(
tree
.
relationship
(
tree
.
get_person
(
cmd
[
1
]),
tree
.
get_person
(
cmd
[
2
])))
except
KeyError
:
print
(
"Error: one or both persons do not exist"
)
elif
cmd
[
0
]
==
"load"
:
try
:
tree
=
openfile
(
cmd
[
1
])
print
(
cmd
[
1
]
+
".ft has been loaded"
)
except
FileNotFoundError
:
print
(
"Error: File not found"
)
elif
cmd
[
0
]
==
"save"
:
tree
.
find_root
()
tree
.
precompute
()
savefile
(
cmd
[
1
],
tree
)
print
(
"file saved"
)
elif
cmd
[
0
]
==
"bye"
:
print
(
"Goodbye!"
)
break
else
:
print
(
"Error: no such command"
)
def
main
():
def
main
():
r"""For testing.
r"""For testing.
...
...
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