Chinese Zodiac - python project

edmundicon at gmail.com edmundicon at gmail.com
Tue Nov 12 23:04:08 CET 2013


Greetings everyone! This is my first post on this forum :)

TL;DR: I want to convert the gregorian years into Chinese years, and deal with the fact that the Chinese new years are different each gregorian year. If I manage to do that, I'll know which year the user is born in Chinese years and can then give him a personal description based upon that year!

I started to learn Python programming language 2 months ago (noob), but I like it and I feel like if I keep learning I might become a great programmer one day!

I recently started a small Python project in which my mission is to give a personal description to a user based upon the year he / she is born in the Chinese Zodiac and I have run into some trouble. For instance, if someone is born on the 15'th January 1990, he is actually born 1989 because the Chinese new year occurred on the 27:th January that year.

I have a text file which shows when the Chinese new years in gregorian years (normal years), starting from 1900-01-31 to 2007-02-18. It goes like this:
1900-1-31
1901-2-19
1902-2-08
1903-1-29
1904-2-16
1905-2-04
1906-1-25 ...(and so on)
2007-02-18 ( I can't see the logic behind this really)

The Chinese calendar is divided into cycles of 60 years each, and each year has a combination of an animal and an element. There are 12 animals and 5 elements, the animals changes each year, and the elements every other year. The current cycle was initiated in the year of 1984 which was the year of the Wood Rat. The personal descriptions for each combination has conveniently also been provided in text files. 

The animals are in this order:

Rat
Ox
Tiger
Rabbit
Dragon
Snake
Horse
Sheep
Monkey
Rooster
Dog
Boar

And the elements are:

Wood
Fire
Earth
Metal
Water

I have already created a modulus method which takes the input year (the gregorian year you were born) and gives you an element and an animal, for example if you type "1990" you are given Metal Horse. The problem I now have is to convert the gregorian years into Chinese years, and deal with the fact that the Chinese new years are different each gregorian year. If I manage to do that, I'll know which year the user is born in Chinese years and can then give him a personal description based upon that year!

Any advice will be greatly appreciated! Have a nice day :)




More information about the Python-list mailing list