Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit be76e3f

Browse files
author
Jinendra Jain
authored
Add files via upload
1 parent 38b505d commit be76e3f

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

‎4.Pattern 2/Code Diamond of stars.ipynb

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"Print the following pattern for the given number of rows.<br>\n",
99
"Note: N is always odd.<br>\n",
1010
"Pattern for N = 5<br>\n",
11-
"![DiamondOfStars](https://ninjasfiles.s3.amazonaws.com/0000000000003726.png)<br>\n",
11+
"![DiamondOfStars](https://imgur.com/download/Xlk5UcG)<br>\n",
1212
"The dots represent spaces.<br>\n",
1313
"Input format :<br>\n",
1414
"N (Total no. of rows and can only be odd)<br>\n",
@@ -67,6 +67,45 @@
6767
" print()\n",
6868
" currRow-=1"
6969
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 1,
74+
"metadata": {},
75+
"outputs": [
76+
{
77+
"name": "stdout",
78+
"output_type": "stream",
79+
"text": [
80+
"9\n",
81+
" *\n",
82+
" ***\n",
83+
" *****\n",
84+
" *******\n",
85+
"*********\n",
86+
" *******\n",
87+
" *****\n",
88+
" ***\n",
89+
" *\n"
90+
]
91+
}
92+
],
93+
"source": [
94+
"#Another Solution\n",
95+
"n=int(input())\n",
96+
"first=n//2+1\n",
97+
"sec=n//2\n",
98+
"#first loop\n",
99+
"for i in range(1,first+1):\n",
100+
" print(\" \"*(first-i),end=\"\")\n",
101+
" print((2*i-1)*\"*\",end=\"\")\n",
102+
" print()\n",
103+
"#Second Loop\n",
104+
"for p in range(1,sec+1):\n",
105+
" print(\" \"*p,end=\"\")\n",
106+
" print((2*(sec-p+1)-1)*\"*\",end=\"\")\n",
107+
" print()"
108+
]
70109
}
71110
],
72111
"metadata": {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /