From a43cc6d25498d8a49e121e79429f219468235693 Mon Sep 17 00:00:00 2001 From: abdulrahman Date: Sat, 25 Sep 2021 22:42:54 +0300 Subject: [PATCH 1/3] had been done --- python_pass.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/python_pass.py b/python_pass.py index 9616d7a..cfd2e65 100644 --- a/python_pass.py +++ b/python_pass.py @@ -10,5 +10,23 @@ class StringOperations: - def reverse(self, *, to_be_reversed: str = None): - raise NotImplemented('This method need to be implemented') + def reverse(self, to_be_reversed): + + string_leangh = len(to_be_reversed) + + + + reversed_string = to_be_reversed + + reversed_string = reversed_string[::-1] + return reversed_string + + + + +class ReversedString(StringOperations): + pass + +string_to_revers = ReversedString() + +print(string_to_revers.reverse("hello world ")) \ No newline at end of file From e333ea6e680256126908cf92f026c5f819cce3e2 Mon Sep 17 00:00:00 2001 From: abdulrahman Date: Sat, 25 Sep 2021 22:56:51 +0300 Subject: [PATCH 2/3] add commints to the code --- python_pass.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/python_pass.py b/python_pass.py index cfd2e65..caba75a 100644 --- a/python_pass.py +++ b/python_pass.py @@ -11,22 +11,23 @@ class StringOperations: def reverse(self, to_be_reversed): - - string_leangh = len(to_be_reversed) - - - + #a copy from input named reversed_string reversed_string = to_be_reversed + #reversing the copy by create a slice that starts with the length of the string, and ends at index 0 reversed_string = reversed_string[::-1] + + #return a reversed copy return reversed_string - +#create a ReversedString class inherting from String operation class class ReversedString(StringOperations): pass +#creat an Instantiate from ReversedString class string_to_revers = ReversedString() -print(string_to_revers.reverse("hello world ")) \ No newline at end of file +#print the output of the reverse function +print(string_to_revers.reverse("hello world ")) From 11f246d36a2c7a39cf311da6bbd5b7502527832a Mon Sep 17 00:00:00 2001 From: abdulrahman Date: Sun, 26 Sep 2021 09:29:54 +0300 Subject: [PATCH 3/3] fixing the function --- python_pass.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/python_pass.py b/python_pass.py index caba75a..2c22749 100644 --- a/python_pass.py +++ b/python_pass.py @@ -11,23 +11,25 @@ class StringOperations: def reverse(self, to_be_reversed): - #a copy from input named reversed_string - reversed_string = to_be_reversed + + return reversed_string + + +# create a ReversedString class inherting from String operation class +class ReversedString(StringOperations): + def reverse(self, to_be_reversed): + # a copy from input named reversed_string + reversed_string = to_be_reversed - #reversing the copy by create a slice that starts with the length of the string, and ends at index 0 + # reversing the copy by create a slice that starts with the length of the string, and ends at index 0 reversed_string = reversed_string[::-1] - - #return a reversed copy + + # return a reversed copy return reversed_string - - -#create a ReversedString class inherting from String operation class -class ReversedString(StringOperations): - pass -#creat an Instantiate from ReversedString class +# creat an Instantiate from ReversedString class string_to_revers = ReversedString() -#print the output of the reverse function +# print the output of the reverse function print(string_to_revers.reverse("hello world "))