Skip to content

Commit 8d76479

Browse files
authored
More efficient way to solve Pattern Program
1 parent 4bcafb6 commit 8d76479

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

Programs/P05_Pattern.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,24 @@ def pattern5(level):
8989
pattern5(userInput)
9090
print()
9191

92-
'''
93-
following is the another approach to solve pattern problems with reduced time complexity
94-
95-
for
96-
97-
*
98-
**
99-
***
100-
****
101-
*****
102-
'''
103-
104-
num = int(input('Enter number for pattern'))
105-
pattern = '*'
106-
string = pattern * num
107-
x = 0
108-
109-
for i in string:
110-
x = x + 1
111-
print(string[0:x])
92+
def pattern6(userInput):
93+
'''
94+
following is the another approach to solve pattern problems with reduced time complexity
95+
96+
for
97+
98+
*
99+
**
100+
***
101+
****
102+
*****
103+
'''
104+
105+
num = int(input('Enter number for pattern'))
106+
pattern = '*'
107+
string = pattern * num
108+
x = 0
109+
110+
for i in string:
111+
x = x + 1
112+
print(string[0:x])

0 commit comments

Comments
 (0)