From 668fa6be8dcb494b12d9d415edbd0a05c55cf83a Mon Sep 17 00:00:00 2001 From: rfamilara Date: Sun, 11 Oct 2020 21:15:26 -0500 Subject: [PATCH 1/2] Completed code for count_th.py -Tests successful --- recursive_count_th/count_th.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/recursive_count_th/count_th.py b/recursive_count_th/count_th.py index 07456a00b..ecad6ac16 100644 --- a/recursive_count_th/count_th.py +++ b/recursive_count_th/count_th.py @@ -5,6 +5,15 @@ ''' def count_th(word): - # TBC + # Verify if the length of the word is not less than "th"; else, it contains it - pass + if len(word) < len('th'): + return 0 + + #Furthermore, verify if the first two letters equals "th", return 1 + elif word[:2] == 'th': + return count_th(word[2:]) + 1 + + #Else, proceed with the next letter of the word + else: + return count_th(word[1:]) From b1badbff9b4c19d0de7487d649ba0180a8badd74 Mon Sep 17 00:00:00 2001 From: rfamilara Date: Sun, 11 Oct 2020 22:07:51 -0500 Subject: [PATCH 2/2] Completed coding robot_sort.py -Tests successful --- robot_sort/robot_sort.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/robot_sort/robot_sort.py b/robot_sort/robot_sort.py index db6b1985b..81c5df273 100644 --- a/robot_sort/robot_sort.py +++ b/robot_sort/robot_sort.py @@ -97,7 +97,28 @@ def sort(self): Sort the robot's list. """ # Fill this out - pass + self.set_light_on() + + while self.light_is_on(): + self.set_light_off() + + while self.can_move_right(): + self.move_right() + + if self.compare_item() == 1: + self.swap_item() + self.set_light_on() + + while self.can_move_left(): + self.swap_item() + self.move_left() + + if self.compare_item() == -1: + self.swap_item() + self.set_light_on() + self.move_right() + self.swap_item() + self.move_left() if __name__ == "__main__":