5 Replies - 1363 Views - Last Post: 08 October 2012 - 06:27 PM Rate Topic: -----

#1 blindchicken11  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 19-September 12

zodiac sign code question

Posted 07 October 2012 - 08:44 PM

Hello all. I'm working on a program where a user enters his birth year, month, and day and then the program computes what their western zodiac and chinese sign are. Right now, for the western zodiac I just have a bunch of if/else statements (i.e. if birth_day > 21: return taurus). For the chinese signs I have a constant for each sign and the years they contain (i.e. if birth_year in Dragon: return dragon). It just seems like there would be an easier/shorter way to do this and if anyone could give me some ideas? Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: zodiac sign code question

#2 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5803
  • View blog
  • Posts: 12,642
  • Joined: 16-October 07

Re: zodiac sign code question

Posted 08 October 2012 - 02:50 AM

Show the code.

For the Chinese, a list is silly. You need only know the year one sign starts, say 1900, and the cycle. It should be rudimentary to take it from there. It doesn't sound like you're considering the lunar year.
Was This Post Helpful? 0
  • +
  • -

#3 blindchicken11  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 19-September 12

Re: zodiac sign code question

Posted 08 October 2012 - 03:42 PM

MONTHS1 = ("january", "february", "march", "april", "may", "june", "july")
MONTHS2 = ("august", "september", "october", "november", "december")

def check_Month(birth_Month):

    if birth_Month in (MONTHS1):
        return birth_Month
    elif birth_Month in (MONTHS2):
        return birth_Month
    else:
        print("\n")
        print("Please run the program again and enter a correct month.")
        sys.exit

def get_Sign(bmonth, bdate):

    if bmonth == "january":
       if bdate > 20:
            return "Aquarius"
        else:
            return "Capricon"

    elif bmonth == "february":
        if bdate > 19:
            return "Pisces"
        else:
            return "Aquarius"

    elif bmonth == "march":
        if bdate > 20:
            return "Aries"
        else:
            return "Pisces"

    elif bmonth == "april":
        if bdate > 20:
            return "Taurus"
        else:
            return "Aries"

    elif bmonth == "may":
        if bdate > 21:
            return "Gemini"
        else:
            return "Taurus"

    elif bmonth == "june":
        if bdate > 21:
            return "Cancer"
        else:
            return "Gemini"

    elif bmonth == "july":
        if bdate > 23:
            return "Leo"
        else:
            return "Cancer"

    elif bmonth == "august":
        if bdate > 23:
            return "Virgo"
        else:
            return "Leo"

    elif bmonth == "september":
        if bdate > 23:
            return "Libra"
        else:
            return "Virgo"

    elif bmonth == "october":
        if bdate > 23:
            return "Scorpio"
        else:
           return "Libra"

    elif bmonth == "november":
        if bdate > 22:
            return "Sagittarius"
        else:
            return "Scorpio"

    elif bmonth == "december":
        if bdate > 22:
            return "Capricon"
        else:
            return "Sagittarius"

    else:
        return

def main():

def main():

    

    birth_Year = input("Please enter your birth year: ")
    birth_Month = raw_input("Please enter your birth month: ").lower()
    birth_date = input("Please enter your birth date: ")

    check_Month(birth_Month)

    west_Sign = get_Sign(birth_Month, birth_date)

    

main()




By lunar year do you mean how the chinese year stars in feb. and not jan.?
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5803
  • View blog
  • Posts: 12,642
  • Joined: 16-October 07

Re: zodiac sign code question

Posted 08 October 2012 - 04:31 PM

View Postblindchicken11, on 08 October 2012 - 06:42 PM, said:

By lunar year do you mean how the chinese year stars in feb. and not jan.?


Yes and sort of. It's a little complex. The Chinese year follows a lunar cycle. There are about 12.3 lunar cycles in a solar cycle. The Chinese use 12 moons to a year, but then chuck in an extra month every three years or so to line their months up with seasons. The Jews use a near identical system. Muslims believe in only 12 moons, so their solar match up has a 60 year drift. Ok, you probably didn't want to know all that. :P

In your code, there is no possible reason for MONTHS1 and MONTHS2 just combine them together as MONTHS. You can also use this to get a month number, which can be helpful:
>>> MONTHS = ("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december")
>>> MONTHS.index('july')
6
>>>


You could make your get sign code drastically shorter by using another list. Something like:
ZODIAC = (("Capricorn", 20), ("Aquarius", 19), ....




Understand, those break days are also rough. Our solar calendar has a 0.25 day drift, which we adjust with leap years. So a solar sign can vary a day before or after the "cusp."

So, what have you tried for Chinese?
Was This Post Helpful? 0
  • +
  • -

#5 blindchicken11  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 19-September 12

Re: zodiac sign code question

Posted 08 October 2012 - 05:42 PM

Yeah the only reason I made two MONTHS is because I can't go over 80 characters per line (no word wrapping). I'm not sure I understand the 2nd code you posted though, what are the numbers for after the signs?
Was This Post Helpful? 0
  • +
  • -

#6 blindchicken11  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 19-September 12

Re: zodiac sign code question

Posted 08 October 2012 - 06:27 PM

For the chinese part I just have another method that takes on the user's year and month and then compares it with the dates in the lists of the chinese horoscopes. But now I'm confused about the whole lunar thing, trying to read up on it but can't find a simple explanation. Everything goes into a lot of detail about it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1