From 7666bc4ed75fa6b860064c46582eccc9b93d81a7 Mon Sep 17 00:00:00 2001 From: Mohamed Adel <55633451+Mohamed66Adel@users.noreply.github.com> Date: Sun, 28 Jul 2024 21:29:33 +0300 Subject: [PATCH 1/2] Update 10_functions_exercise.py in [print_pattern()] fn, the inner loop is replaced with one line print(i * '*') --- Basics/Exercise/10_functions/10_functions_exercise.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Basics/Exercise/10_functions/10_functions_exercise.py b/Basics/Exercise/10_functions/10_functions_exercise.py index da953df9..a23e19af 100644 --- a/Basics/Exercise/10_functions/10_functions_exercise.py +++ b/Basics/Exercise/10_functions/10_functions_exercise.py @@ -14,13 +14,9 @@ def print_pattern(n=5): supply the input number then it will assume it to be 5 :return: None ''' - # we need to run two for loops. Outer loop prints patterns line by line - # where as inner loop print the content of that specific lines + # we need to run one for loops. Outer loop prints patterns line by line for i in range(n): - s = '' - for j in range(i+1): - s = s + '*' - print(s) + print('*' * i) def calculate_area(dimension1,dimension2,shape="triangle"): ''' @@ -87,4 +83,4 @@ def calculate_area(dimension1,dimension2,shape="triangle"): print("Print pattern with input=4") print_pattern(4) print("Print pattern with no input number") -print_pattern() # Not supplying any input will use default argument which is 5 \ No newline at end of file +print_pattern() # Not supplying any input will use default argument which is 5 From 655bdde7b9daebc2fc58def19e062f1a981819d9 Mon Sep 17 00:00:00 2001 From: Mohamed Adel <55633451+Mohamed66Adel@users.noreply.github.com> Date: Sun, 28 Jul 2024 21:48:35 +0300 Subject: [PATCH 2/2] Update 10_functions_exercise.py --- Basics/Exercise/10_functions/10_functions_exercise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Basics/Exercise/10_functions/10_functions_exercise.py b/Basics/Exercise/10_functions/10_functions_exercise.py index a23e19af..e7ebf9bb 100644 --- a/Basics/Exercise/10_functions/10_functions_exercise.py +++ b/Basics/Exercise/10_functions/10_functions_exercise.py @@ -15,7 +15,7 @@ def print_pattern(n=5): :return: None ''' # we need to run one for loops. Outer loop prints patterns line by line - for i in range(n): + for i in range(1, n+1): print('*' * i) def calculate_area(dimension1,dimension2,shape="triangle"):