-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
def reverse(s): | ||
if not s: | ||
return "" | ||
return reverse(s[1:])+s[0] | ||
|
||
def count_specific_char_in_string(s,_char): | ||
if not s: | ||
return 0 | ||
if s[0]==_char: | ||
return 1 + count_specific_char_in_string(s[1:],_char) | ||
else: | ||
return count_specific_char_in_string(s[1:],_char) | ||
|
||
|
||
if __name__ == '__main__': | ||
print(f"!NataSha = {reverse('!NataSha')}") | ||
|
||
str = "axbxcx" | ||
c = "x" | ||
print(f"{c} in {str} is repeated {count_specific_char_in_string(str,c)} times") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def sum_of_numbers(array): | ||
if not array: | ||
return 0 | ||
# this statement is not needed because , a[1:] on an array with one value will give empty array | ||
#if(len(array))==1: | ||
#return array[0] | ||
return array[0]+sum(array[1:]) | ||
|
||
|
||
if __name__ == '__main__': | ||
arr = [1,2,3,4] | ||
print(f"sum of {arr} is {sum_of_numbers(arr)}") | ||
|
||
arr = [10,20,3,14] | ||
print(f"sum of {arr} is {sum_of_numbers(arr)}") |