forked from piyush-kash/Hacktober2021-cpp-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bowtie.py
55 lines (46 loc) · 1.07 KB
/
bowtie.py
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
/*
BowTie Pattern:
Complete the given method solve that takes as parameter an integer n and prints a formation like the examples below.
Hint: Is there a relation between row number and the number of *? What about row number and number of .?
Example Input: 1
Example Output:
*.*
***
*.*
Example Input: 5
Example Output:
*.........*
**.......**
***.....***
****...****
*****.*****
***********
*****.*****
****...****
***.....***
**.......**
*.........*
*/
def solve(n):
# write your code here
col=2*n+1
#for i in range(1,n+1):
for r in range(1,n+1):
for c in range(1,col+1):
if(r>=c or c>=(col-r+1)):
print("*",end="")
else:
print(".",end="")
print()
#print()
for i in range(col):
print("*",end="")
print()
for r in range(n,0,-1):
for c in range(1,col+1):
if(r>=c or c>=(col-r+1)):
print("*",end="")
else:
print(".",end="")
print()
print()