Den tisdagen den 12:e november 2013 kl. 23:50:03 UTC+1 skrev Denis McMahon:
> On Tue, 12 Nov 2013 14:04:08 -0800, edmundicon wrote:
>
>
>
> > 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 :)
>
>
>
> Here is one suggestion
>
>
>
> Write a function to convert a gregorian date into the number of days
>
> since 1st January 1900 (we'll call 1st january 1900 your epoch). You will
>
> need to take leap years into account.
>
>
>
> Convert the users date of birth using this function.
>
>
>
> Convert your chinese new year dates using this function.
>
>
>
> You now have the simple task of comparing the users date of birth as
>
> daynumber_since_epoch with the start date of each chinese year as
>
> daynumber_since_epoch.
>
>
>
> You may wish to create a list of tuples where each tuple has start_day,
>
> end_day, year_name:
>
>
>
> years = [(0,30,"stone pig"),(31,414,"stone weasel") ... ]
>
>
>
> You should be able to automate creating this list.
>
>
>
> You could then search through the list of tuples with a function such as:
>
>
>
> yearname( birthdate ):
>
> foreach thing in years
>
> if birthdate is in the range specified by the thing
>
> return the yearname from the thing
>
> return "constipated program"
>
>
>
> (this is obviously not written as python code, you have to do that bit
>
> yourself)
>
>
>
> --
>
> Denis McMahon, denismfmcma...@gmail.com
Sir, I am really happy that you answered, but could you *please* elaborate /
give more great advice on how to write the function which converts your
gregorian date into a Chinese year?
Should I do it like t