Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update 10_functions_exercise.py
in [print_pattern()] fn, the inner loop is replaced with one line 
print(i * '*')
  • Loading branch information
Mohamed66Adel authored Jul 28, 2024
commit 7666bc4ed75fa6b860064c46582eccc9b93d81a7
10 changes: 3 additions & 7 deletions Basics/Exercise/10_functions/10_functions_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
'''
Expand Down Expand Up @@ -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
print_pattern() # Not supplying any input will use default argument which is 5