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>Actually, year%100 returns the decade quite nicely.</p>

<p>here is the finished version of my program that works...</p>

<pre><code>critters=('Rat','ox', 'tiger','rabbit', 'dragon', 'snake', 'horse', 'ram', 'monkey', 'rooster', 'dog', 'pig')

def docrit(yrint):
    modval=yrint%12
    return critters[modval]

def wieder():
    go=input('Again[y,n]')
    if go=='y':
      return True
    else:
      return False

def main():
    print('Chinese Zodiac Calculator')
    yob=int(input('year: '))
    cent=int(yob/100)
    decade=yob%100
    print('century: ',cent)
    print('decade: ',decade)
    ani=docrit(decade)
    print('the animal is ',ani)
    if wieder()== True:
      main()
    else:
      exit()

def exit():
    print("I'm done. Bye.")
    return 0

main()
</code></pre>

python