- Notifications
You must be signed in to change notification settings - Fork 638
Expand file tree
/
Copy pathP05_Pattern.py
More file actions
Latest commit
112 lines (90 loc) · 2 KB
/
Copy pathP05_Pattern.py
File metadata and controls
112 lines (90 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#Author: OMKAR PATHAK
#This program prints various patterns
defpattern1(level):
'''This function prints the following pattern:
*
**
***
****
'''
foriinrange(1, level+1):
print()
forjinrange(i):
print('*', end='')
defpattern2(level):
'''This function prints the following pattern:
****
***
**
*
'''
foriinrange(level, 0, -1):
print()
forjinrange(i):
print('*', end='')
defpattern3(level):
'''This function prints the following pattern:
*
**
***
****
'''
counter=level
foriinrange(level+1):
print(' '*counter+'*'*i)
counter-=1
defpattern4(level):
'''This function prints the following pattern:
****
***
**
*
'''
counter=0
foriinrange(level, 0 ,-1):
print(' '*counter+'*'*i)
counter+=1
defpattern5(level):
'''This function prints the following pattern:
*
***
*****
'''
# first loop for number of lines
foriinrange(level+1):
#second loop for spaces
forjinrange(level-i):
print (" ",end='')
# this loop is for printing stars
forkinrange(2*i-1):
print("*", end='')
print()
if__name__=='__main__':
userInput=int(input('Enter the level: '))
pattern1(userInput)
print()
pattern2(userInput)
print()
pattern3(userInput)
print()
pattern4(userInput)
print()
pattern5(userInput)
print()
defpattern6(userInput):
'''
following is the another approach to solve pattern problems with reduced time complexity
for
*
**
***
****
*****
'''
num=int(input('Enter number for pattern'))
pattern='*'
string=pattern*num
x=0
foriinstring:
x=x+1
print(string[0:x])