Free AI web copilot to create summaries, insights and extended knowledge, download it at here
1993
Abstract
dual digits.</p><p id="d968">Once the loop ends, we are comparing the values of n and s and printing the appropriate output.</p><p id="1ac1">Here:</p><ol><li>n is input</li><li>d is digit</li><li>s is sum of the ‘digits power 3’</li></ol><p id="414a">Now, let’s see how we can use the above code to determine Armstrong number for n digits. Once you are familiar with the above code for 3 digit number, with small tweak to your code, you can check for n number of digits in a number.</p>
<figure id="9e19">
<div>
<div>
<iframe class="gist-iframe" src="/gist/Kaushik-Varma/f7357a395b6b075a65b596967b72ef60.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="7e6a">If you observe in the above code, we took another variable ‘p’ in line #2, to find out the number of digits the input number has, so that we know the power of each digit while adding, which we have done in line #7.</p><h2 id="c242">2. Fenced Matrix</h2><p id="8051">While learning Python Programming, often we will come across the concept of 2-D Arrays also known as Matrix. While learning the Matrix, you’ll be asked to create a specific type of Matrix called as Fenced Matrix.</p><h2 id="a100">What is a Fenced Matrix?</h2><figure id="f8cc"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*M3VH4a40Z7pvWtRJ6bmDyQ.jpeg"><figcaption>Fenced Matrix</figcaption></figure><p id="2b65">You have to make a list of lists of size m*n, that is m sub-lists (rows), with each sub-lists having n integers (columns). The matrix should be such that it should have 1 on the border and 0 everywhere else.</p><p id="4bba">Let’s see how we can write a program for that. Before proceeding further I strongly suggest to attempt to write the code yourselves first.</p><p id="be7b" type="7">To understand the code, one should have an understanding abo
Options
ut some of the Python Programming topics:</p><p id="d481" type="7">i) Python if….else statements</p><p id="afa7" type="7">ii) Python nested for loops</p>
<figure id="0348">
<div>
<div>
<iframe class="gist-iframe" src="/gist/Kaushik-Varma/e6d62b6370889c875e123d5c72f7294d.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="a278">Here, we are taking input (no.of rows & no. of columns) and converting them into a single list.</p><p id="cdf5">“m” is no. of rows</p><p id="9b11">‘‘n’’ is no. columns.</p><p id="a158">In line #6 we are creating a list of zeroes, which has ’n’ elements in single row. In line #8 we are extending that single row of list into ‘m’ no. of rows which contains only zeroes.</p><p id="d0d0">Now, by using nested for loops and if statements as shown, we are creating <b>Fenced Matrix </b>which has element ‘1’ on the border and ‘0’ everywhere else.</p><p id="a221">The output will look like this</p><div id="41e7"><pre><span class="hljs-attribute">4</span>,<span class="hljs-number">5</span><span class="hljs-meta">
[1, 1, 1, 1, 1]</span><span class="hljs-meta">
[1, 0, 0, 0, 1]</span><span class="hljs-meta">
[1, 0, 0, 0, 1]</span><span class="hljs-meta">
[1, 1, 1, 1, 1]</span></pre></div><p id="bcdc">Here ‘4’ is no. of rows and ‘5’ is no. of columns.</p><h2 id="b9ec">Conclusion</h2><p id="8f71">Finally, this is how one can check for <b>Armstrong Number</b> and can print <b>Fenced Matrix</b></p><p id="49e1">You can also check my previous article <a href="https://medium.com/@kaushikvarma.katari/python-problems-for-basics-reference-swapping-factorial-reverse-digits-pattern-print-241dde763c74?source=friends_link&sk=2e5bf5b0ace69c8bbdcce194b12175e0">Python: Problems for Basics Reference</a></p><p id="4d53">Thank you for reading and Happy Coding!!!!</p></article></body>