Division & Modulo Operator
<p>I just started learning how to code, and I've been assigned a problem that I've been stuck on for many hours now and was hoping I could receive some hints at the very least to solve the problem. The main point of this exercise is to practice division and modulus. We can use basic statements,  but nothing fancy like conditionals or anything since we haven't gotten to that point.</p>

<p>I need a user to input a # from 1 - 25, and then my program will let them know which unit and row that number is in. I've managed to get the code working for the rows, but I cannot figure out how to get the unit number.</p>

<p>Here's my code:</p>

<pre><code>shelfNumber = int(raw_input('What is the shelf number? '))
row = int(shelfNumber / 5.1) + 1
unit = 
</code></pre>

<p>I've tried a lot of things for unit, but none of them worked out, so I left it blank. I would appreciate any hints that anyone can give me. Thank you for any help.</p>

<p><a href="http://i.stack.imgur.com/qNiAe.png" rel="nofollow"><img src="http://i.stack.imgur.com/qNiAe.png" alt="image"></a></p>

<p>Edit: I realized that I should try and at least show which ideas I've tried. If I do a regular modulo with # % 5, that works for everything but the multiples of 5 all the way on the right. I've also tried implementing the row #'s each # has but haven't gotten anywhere with that either. I've also tried something similar by dividing by a decimal, casting it as an int, then using modulo but failed, etc., etc.\</p>

<p><strong>Edit:</strong> Sorry, I realized I uploaded the wrong image.</p>

<p>This problem would be easier if everything were countrd from 0 instead of from 1. That is, if the row and unit numbers were 0 to 4 instead of 1 to 5 and if the input value were 0 to 24 instead of 1 to 25.</p>

<p>In that case, we'd just write:</p>

<pre><code>row = shelfNumber / 5
unit = shelfNumber % 5
</code></pre>

<p>Since everything starts ftom 1 ("is one-indexed" in the usual jargon), <code>shelfNumber</code> is one bigger than what that formula needs, and we need to make <code>row</code> and <code>unit</code> one bigger than what we computed.</p>

<p>But there's no trouble fixing that:</p>

<pre><code>row = (shelfNumber - 1) / 5 + 1
unit = (shelfNumber - 1) % 5 + 1
</code></pre>

<p>In Python 3, you'd need to write <code>//</code> insted of <code>/</code>, and that will work with a reasonably recent Python 2.</p>

python python-2.x division modulo modulus