Separating decades and centuries in python
<p>I have a program I'm creating where I need to be able to take a year, as an integer, and separate the century from the decade:</p>

<pre><code>year=1970
decade=70
century=1900
</code></pre>

<p>I want to be able to do this:</p>

<pre><code>year= new Year(1970)
dec= year.decade
cent=year.century
</code></pre>

<p>I know I'll have to create a Year object and implement those two methods, but my issue is in the math, how do I take a year and extract just the decade and/or century?</p>

<p>I had tried passing it to a function as a string then building an integer out of the last two values in the string, but I ran into trouble with data types and want a 'native integer' way of doing this.</p>

<p>Thanks in advance!</p>

<p>Stormy</p>

<p>Divide the year by 100 (integer only). The result is the century:</p>

<pre><code>1972 / 100 = 19
</code></pre>

<p>(Of course, multiply again with 100 to get 1900).</p>

<p>The remainder is the year within that century:</p>

<pre><code>1972 - (19 * 100) = 72
</code></pre>

<p>Do the same if you want to get the decade of the year with 10:</p>

<pre><code>72 / 10 = 7
</code></pre>

python