diff --git a/homeworks/09_Elena_Varbanova/09_Elena_Varbanova:01_check_circles.py b/homeworks/09_Elena_Varbanova/01_check_circles.py similarity index 100% rename from homeworks/09_Elena_Varbanova/09_Elena_Varbanova:01_check_circles.py rename to homeworks/09_Elena_Varbanova/01_check_circles.py diff --git a/homeworks/09_Elena_Varbanova/replace.py b/homeworks/09_Elena_Varbanova/replace.py new file mode 100644 index 0000000..de4ff53 --- /dev/null +++ b/homeworks/09_Elena_Varbanova/replace.py @@ -0,0 +1,38 @@ +def replace(listing, finding, replacing): + counter = 0 + + for index in listing: + + if type(index) != int and len(index) > 1: + + if type(index) == tuple: + new_list = list(listing[counter]) + new_list = replace(new_list, finding, replacing) + listing[counter] = tuple(new_list) + + else: + new_list = listing[counter] + new_list = replace(new_list, finding, replacing) + + if index == finding: + listing[counter] = replacing + + counter = counter + 1 + + return listing + +listing = [ 'a', 1, [ ['a', 'b'], 1], ([1, 3, 'a'], 'a')]#last 'a' in English +res = replace(listing, 'a', 'c') +print(res)#[ 'c', 1, [ ['c', 'b'], 1], ([1, 3, 'c'], 'b')] + +print("...........") + +list1 = [ 'a', 1, [ ['a', 'b'], 1], ([1, 3, 'a'], 'а')]#last 'a' in Bulgarian +res1 = replace(list1, 'a', 'c') +print(res1)#[ 2, 'e', [ ['a', 'b'], 'c'], (['e', 3, 2], 'a')] + +print("...........") + +list2 = [ 2, 1, [ ['a', 'b'], 'c'], ([1, 3, 2], 1)] +res2 = replace(list2, 1, 'e') +print(res2)#[ 2, 'e', [ ['a', 'b'], 'c'], (['e', 3, 2], 'b')] diff --git a/homeworks/09_Elena_Varbanova/step_counter.py b/homeworks/09_Elena_Varbanova/step_counter.py new file mode 100644 index 0000000..4310251 --- /dev/null +++ b/homeworks/09_Elena_Varbanova/step_counter.py @@ -0,0 +1,18 @@ +def fibonacci(number): + if number <= 1: + return number + return fibonacci(number - 1) + fibonacci(number - 2) + + +def num_ways(num): + return fibonacci(num + 1) + + +stair1 = 2 +print("Number of ways:", num_ways(stair1)) + +stair2 = 3 +print("Number of ways:", num_ways(stair2)) + +stair3 = 4 +print("Number of ways:", num_ways(stair3))