From 5f615dc00a6893970ea12ae6ca277db6708c7ea6 Mon Sep 17 00:00:00 2001 From: vfarenjiya <120475570+vfarenjiya@users.noreply.github.com> Date: Sun, 26 Mar 2023 16:35:29 +0530 Subject: [PATCH] OnlyOneForLoop.py --- Basics/Exercise/10_functions/10_functions_exercise.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Basics/Exercise/10_functions/10_functions_exercise.py b/Basics/Exercise/10_functions/10_functions_exercise.py index da953df9..99e6bcf1 100644 --- a/Basics/Exercise/10_functions/10_functions_exercise.py +++ b/Basics/Exercise/10_functions/10_functions_exercise.py @@ -16,11 +16,16 @@ def print_pattern(n=5): ''' # 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 - for i in range(n): + '''for i in range(n): s = '' for j in range(i+1): s = s + '*' - print(s) + print(s)''' + #we can also do this by using only one for loop + n=int(input("Enter number")) + for i in range(1,n+1): + print("*"*i) + def calculate_area(dimension1,dimension2,shape="triangle"): ''' @@ -87,4 +92,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