Free AI web copilot to create summaries, insights and extended knowledge, download it at here
5329
Abstract
mber">1</span>)</pre></div><div id="84f6"><pre><span class="hljs-symbol">2 </span><span class="hljs-number">3</span>
<span class="hljs-symbol">4 </span><span class="hljs-number">5</span>
<span class="hljs-symbol">6 </span><span class="hljs-number">7</span></pre></div><p id="2eea">Let’s review <i># <b>Python end parameter in print()</b> too:</i></p><div id="bba0"><pre><span class="hljs-built_in">print</span>(<span class="hljs-string">"Welcome to"</span> , end = <span class="hljs-string">' '</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">"GeeksforGeeks"</span>, end = <span class="hljs-string">' '</span>)</pre></div><div id="42b5"><pre>Welcome <span class="hljs-keyword">to</span> GeeksforGeeks</pre></div><p id="f4e3">It ends line by <i>space</i> instead of <i>\n</i>.</p><p id="6d47">Look here we did not call parameter in the first print:</p><div id="c38b"><pre><span class="hljs-built_in">print</span>(<span class="hljs-string">"Welcome to"</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">"GeeksforGeeks"</span>, end = <span class="hljs-string">' '</span>)</pre></div><div id="f94c"><pre>Welcome <span class="hljs-keyword">to</span>
GeeksforGeeks</pre></div><h1 id="3b4c">MARIO'S PYRAMID</h1><h2 id="db0c">for inside for</h2><div id="46e6"><pre><span class="hljs-comment"># Mario's pyramid upside down :)</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, <span class="hljs-number">4</span>):
<span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>,<span class="hljs-number">4</span>-i):
<span class="hljs-built_in">print</span>(<span class="hljs-string">'#'</span>, end=<span class="hljs-string">" "</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">''</span>)</pre></div><div id="8d34"><pre># # # #
#
#</pre></div><p id="eea8">Now :</p><div id="405f"><pre><span class="hljs-comment"># Mario's pyramid left alignment:)</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, <span class="hljs-number">4</span>):
<span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>,i+<span class="hljs-number">1</span>):
<span class="hljs-built_in">print</span>(<span class="hljs-string">'#'</span>, end=<span class="hljs-string">" "</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">''</span>)</pre></div><div id="e88e"><pre>#
#
# # #</pre></div><h2 id="8afc">Just while loop to ask and for to print</h2><div id="bdc5"><pre><span class="hljs-comment"># Mario's Pyramid right alignment:)</span>
<span class="hljs-comment"># asks numbers between 0 and 8</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">'Height: '</span>, end=<span class="hljs-string">' '</span>)
h = <span class="hljs-built_in">int</span>(<span class="hljs-built_in">input</span>());
<span class="hljs-keyword">while</span>(h<<span class="hljs-number">0</span> <span class="hljs-keyword">or</span> h > <span class="hljs-number">8</span>):
<span class="hljs-built_in">print</span>(<span class="hljs-string">"That is an invalid input"</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">'Height: '</span>, end=<span class="hljs-string">''</span>)
h = <span class="hljs-built_in">int</span>(<span class="hljs-built_in">input</span>())
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(h):
<span class="hljs-built_in">print</span>(<span class="hljs-string">" "</span>(h-i)+<span class="hljs-string">"#"</span>(i+<span class="hljs-number">1</span>))</pre></div><div id="da60"><pre>Height: <span class="hljs-number">4</span>
#
####</pre></div><p id="9b35">A different for:</p><div id="4951"><pre><span class="hljs-comment"># The counter's range is toyed with here</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, h + <span class="hljs-number">1</span>):
<span class="hljs-comment"># The "i + 1" is removed </span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">" "</span> * (h - i) + <span class="hljs-string">"#"</span> * i)</pre></div><div id="3c14"><pre> #
####</pre></div><h2 id="0a57">Step by step solution:</h2><h2 id="a9f8">#first:</h2><div id="333a"><pre><span class="hljs-comment"># Printing space</span>
h=<span class="hljs-number">4</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(h):
<span class="hljs-built_in">print</span>(<span class="hljs-string">" "</span>*(h-i));</pre></div><figure id="7f2c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*hnVAd_NPrFZQpYvH1momug.png"><figcaption>Just space…</figcaption></figure><p id="116a">Single Hash by line:</p><div id="c1de"><pre><span class="hlj
Options
s-comment"># Printing 1 hash at the end of spaces</span>
h=<span class="hljs-number">4</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(h):
<span class="hljs-built_in">print</span>(<span class="hljs-string">" "</span>*(h-i)+<span class="hljs-string">"#"</span>)</pre></div><div id="8fb5"><pre> <span class="hljs-meta">#</span>
<span class="hljs-meta">#</span>
<span class="hljs-meta">#</span>
<span class="hljs-meta">#</span></pre></div><p id="4125">Final result:</p><div id="8bce"><pre><span class="hljs-comment"># Printing the whole Mari's Pyramid</span>
h=<span class="hljs-number">4</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(h):
<span class="hljs-built_in">print</span>(<span class="hljs-string">" "</span>(h-i)+<span class="hljs-string">"#"</span>(i+<span class="hljs-number">1</span>))</pre></div><div id="9f03"><pre> #
####</pre></div><p id="65e2">Double Pyrami, using <code>while</code> + <code>for</code>:</p><div id="a7ac"><pre><span class="hljs-built_in">print</span>(<span class="hljs-string">'Height: '</span>, end=<span class="hljs-string">''</span>);
h = <span class="hljs-built_in">int</span>(<span class="hljs-built_in">input</span>());
<span class="hljs-keyword">while</span>(h<<span class="hljs-number">0</span> <span class="hljs-keyword">or</span> h > <span class="hljs-number">8</span>):
<span class="hljs-built_in">print</span>(<span class="hljs-string">"That is an invalid input"</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">'Height: '</span>, end=<span class="hljs-string">''</span>);
h = <span class="hljs-built_in">int</span>(<span class="hljs-built_in">input</span>());
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(h):
<span class="hljs-built_in">print</span>(<span class="hljs-string">" "</span>(h-i)+<span class="hljs-string">"#"</span>(i+<span class="hljs-number">1</span>)+ <span class="hljs-string">" "</span>+<span class="hljs-string">"#"</span>*(i+<span class="hljs-number">1</span>));</pre></div><div id="f538"><pre>Height: <span class="hljs-number">4</span>
# #
####</pre></div><p id="7756">Enough o/</p><div id="8147"><pre><span class="hljs-built_in">print</span>(<span class="hljs-string">"That's it, folks. This is CS50! Harvard course, man \o/"</span>)</pre></div><div id="0573"><pre>That<span class="hljs-symbol">'s</span> it, folks. This <span class="hljs-keyword">is</span> CS50! Harvard course, man \o/</pre></div><p id="e4e0">That’s all, folks!</p><p id="0ae7">See you soon o/</p><p id="838b">Bye!</p><p id="91e2">👉Jupiter notebook <a href="https://drive.google.com/file/d/1AZA44fmc4kBNKb1Lj9mepIbxA5c2nKXD/view?usp=sharing">link</a> :)</p><p id="3ae1">👉<a href="https://github.com/giljr/my_jupyter_notebook/tree/master/PPY_10">git</a></p><h2 id="9f64">Credits & References</h2><p id="a8ba"><a href="https://www.harvard.edu/">Harvard University</a></p><p id="fe64"><a href="https://www.estudar.org.br/">Fundacao Estudar</a></p><h1 id="cea0">Related Posts</h1><p id="d220"><b>00</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/lambda-in-python-421b0c18e825"><b>Lambda in Python </b></a>— Python Lambda Desmistification</p><p id="f0d4"><b>01</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/send-emails-using-python-jupyter-notebook-94d14a5a5655"><b>Send Email in Python</b></a> — Using Jupyter Notebook — How To Send Gmail In Python</p><p id="db50"><b>02</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/automate-your-email-marketing-with-python-f0d68234b789"><b>Automate Your Email With Python & Outlook</b></a><b> </b>— How To Create An Email Trigger System in Python</p><p id="36de"><b>03</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/manipulating-files-with-python-3f9a781287e9"><b>Manipulating Files With Python</b></a> — Manage Your Lovely Photos With Python!</p><p id="aa26"><b>04</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/pandas-dataframe-advanced-48f83a5b097f"><b>Pandas DataFrame Advanced </b></a>— A Complete Notebook Review</p><p id="9756"><b>05</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/is-this-leap-year-python-calendar-3d1a61f2c4a7"><b>Is This Leap Year? Python Calendar</b> </a>— How To Calculate If The Year Is Leap Year and How Many Days Are In The Month</p><p id="de8a"><b>06</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/list-comprehension-in-python-c22c4b0a6a8a"><b>List Comprehension In Python </b></a>— Locked-in Secrets About List Comprehension</p><p id="7cc9"><b>07</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/graphs-in-python-b7d243737b77"><b>Graphs — In Python </b></a>— Extremely Simple Algorithms in Python</p><p id="0486"><b>08</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/decorator-in-python-62c00f7e818"><b>Decorator in Python </b></a>— How To Simplifying Your Code And Boost Your Function</p><p id="4505"><b>10</b>#Episode#PurePythonSeries — CS50 — A Taste of Python — Harvard Mario’s Challenge Solver (this one)</p></article></body>