📜  显示给定出生日期的星座或黄道十二宫的Python程序

📅  最后修改于: 2020-05-19 04:47:17             🧑  作者: Mango

对于给定的出生日期,此程序显示星象或黄道十二宫。
例子 :

输入:天= 10,月=十二月
输出:射手座
说明:
在这个日期出生的人是射手座

输入:天= 7,月= 9月
输出:处女座

方法:
尽管确切的日期可能会改变正负的一天,具体取决于年份,但这是西方(或热带)占星术使用的一般星座日期:

西方占星术星座:
白羊座(3月21日至4月19日)
金牛座(4月20日至5月20日)
双子座(5月21日至6月20日)
巨蟹座(6月21日至7月22日)
狮子座(7月23日至8月22日)
处女座(8月23日至9月22日)
天秤座(9月23日至10月22日)
天蝎座(10月23日至11月21日)
射手座(11月22日至12月21日)
摩羯座(12月22日至1月19日)
水瓶座(1月20日至2月18日)
双鱼座(2月19日至3月20日)

我们需要检查我们提到的日期和月份,从而找到其等效的十二生肖,即哪个生肖适合该特定日期以及月份,并打印其相应的十二生肖。
下面是上述方法的实现:
C++:

// CPP程序显示给定的出生日期的星座或黄道十二宫
#include 
using namespace std;
void zodiac_sign(int day, string month)
{
    string astro_sign="";
    // 检查指定生肖有效范围内的月份和日期
    if (month == "december"){
        if (day < 22)
        astro_sign = "Sagittarius";
        else
        astro_sign ="capricorn";
    }
    else if (month == "january"){
        if (day < 20)
        astro_sign = "Capricorn";
        else
        astro_sign = "aquarius";
    }
    else if (month == "february"){
        if (day < 19)
        astro_sign = "Aquarius";
        else
        astro_sign = "pisces";
    }
    else if(month == "march"){
        if (day < 21)
        astro_sign = "Pisces";
        else
        astro_sign = "aries";
    }
    else if (month == "april"){
        if (day < 20)
        astro_sign = "Aries";
        else
        astro_sign = "taurus";
    }
    else if (month == "may"){
        if (day < 21)
        astro_sign = "Taurus";
        else
        astro_sign = "gemini";
    }
    else if( month == "june"){
        if (day < 21)
        astro_sign = "Gemini";
        else
        astro_sign = "cancer";
    }
    else if (month == "july"){
        if (day < 23)
        astro_sign = "Cancer";
        else
        astro_sign = "leo";
    }
    else if( month == "august"){
        if (day < 23)
        astro_sign = "Leo";
        else
        astro_sign = "virgo";
    }
    else if (month == "september"){
        if (day < 23)
        astro_sign = "Virgo";
        else
        astro_sign = "libra";
    }
    else if (month == "october"){
        if (day < 23)
        astro_sign = "Libra";
        else
        astro_sign = "scorpio";
    }
    else if (month == "november"){
        if (day < 22)
        astro_sign = "scorpio";
        else
        astro_sign = "sagittarius";
    }
    cout<

Java:

// Java程序,用于显示给定的出生日期的占星术迹象或黄道十二宫
import Java.io.*;
class GFG {
    static void zodiac_sign(int day, String month)
    {
        String astro_sign="";
        // checks month and date within the
        // valid range of a specified zodiac
        if (month == "december"){
            if (day < 22)
            astro_sign = "Sagittarius";
            else
            astro_sign ="capricorn";
        }
        else if (month == "january"){
            if (day < 20)
            astro_sign = "Capricorn";
            else
            astro_sign = "aquarius";
        }
        else if (month == "february"){
            if (day < 19)
            astro_sign = "Aquarius";
            else
            astro_sign = "pisces";
        }
        else if(month == "march"){
            if (day < 21)
            astro_sign = "Pisces";
            else
            astro_sign = "aries";
        }
        else if (month == "april"){
            if (day < 20)
            astro_sign = "Aries";
            else
            astro_sign = "taurus";
        }
        else if (month == "may"){
            if (day < 21)
            astro_sign = "Taurus";
            else
            astro_sign = "gemini";
        }
        else if( month == "june"){
            if (day < 21)
            astro_sign = "Gemini";
            else
            astro_sign = "cancer";
        }
        else if (month == "july"){
            if (day < 23)
            astro_sign = "Cancer";
            else
            astro_sign = "leo";
        }
        else if( month == "august"){
            if (day < 23)
            astro_sign = "Leo";
            else
            astro_sign = "virgo";
        }
        else if (month == "september"){
            if (day < 23)
            astro_sign = "Virgo";
            else
            astro_sign = "libra";
        }
        else if (month == "october"){
            if (day < 23)
            astro_sign = "Libra";
            else
            astro_sign = "scorpio";
        }
        else if (month == "november"){
            if (day < 22)
            astro_sign = "scorpio";
            else
            astro_sign = "sagittarius";
        }
        System.out.println(astro_sign);
    }
    // 测试代码
    public static void main (String[] args)
    {
        int day = 19;
        String month = "may";
        zodiac_sign(day, month);
    }
}

Python:

# Python程序显示给定出生日期的占星术迹象或黄道十二宫
def zodiac_sign(day, month):
    # 检查指定生肖有效范围内的月份和日期
    if month == 'december':
        astro_sign = 'Sagittarius' if (day < 22) else 'capricorn'
    elif month == 'january':
        astro_sign = 'Capricorn' if (day < 20) else 'aquarius'
    elif month == 'february':
        astro_sign = 'Aquarius' if (day < 19) else 'pisces'
    elif month == 'march':
        astro_sign = 'Pisces' if (day < 21) else 'aries'
    elif month == 'april':
        astro_sign = 'Aries' if (day < 20) else 'taurus'
    elif month == 'may':
        astro_sign = 'Taurus' if (day < 21) else 'gemini'
    elif month == 'june':
        astro_sign = 'Gemini' if (day < 21) else 'cancer'
    elif month == 'july':
        astro_sign = 'Cancer' if (day < 23) else 'leo'
    elif month == 'august':
        astro_sign = 'Leo' if (day < 23) else 'virgo'
    elif month == 'september':
        astro_sign = 'Virgo' if (day < 23) else 'libra'
    elif month == 'october':
        astro_sign = 'Libra' if (day < 23) else 'scorpio'
    elif month == 'november':
        astro_sign = 'scorpio' if (day < 22) else 'sagittarius'
    print(astro_sign)
# 测试代码
if __name__ == '__main__':
    day = 19
    month = "may"
    zodiac_sign(day, month)

C#:

// C#程序显示给定出生日期的占星术迹象或十二生肖
using System;
class GFG {
    static void zodiac_sign(int day, string month)
    {
        string astro_sign="";
        // 检查指定生肖有效范围内的月份和日期
        if (month == "december"){
            if (day < 22)
            astro_sign = "Sagittarius";
            else
            astro_sign ="capricorn";
        }
        else if (month == "january"){
            if (day < 20)
            astro_sign = "Capricorn";
            else
            astro_sign = "aquarius";
        }
        else if (month == "february"){
            if (day < 19)
            astro_sign = "Aquarius";
            else
            astro_sign = "pisces";
        }
        else if(month == "march"){
            if (day < 21)
            astro_sign = "Pisces";
            else
            astro_sign = "aries";
        }
        else if (month == "april"){
            if (day < 20)
            astro_sign = "Aries";
            else
            astro_sign = "taurus";
        }
        else if (month == "may"){
            if (day < 21)
            astro_sign = "Taurus";
            else
            astro_sign = "gemini";
        }
        else if( month == "june"){
            if (day < 21)
            astro_sign = "Gemini";
            else
            astro_sign = "cancer";
        }
        else if (month == "july"){
            if (day < 23)
            astro_sign = "Cancer";
            else
            astro_sign = "leo";
        }
        else if( month == "august"){
            if (day < 23)
            astro_sign = "Leo";
            else
            astro_sign = "virgo";
        }
        else if (month == "september"){
            if (day < 23)
            astro_sign = "Virgo";
            else
            astro_sign = "libra";
        }
        else if (month == "october"){
            if (day < 23)
            astro_sign = "Libra";
            else
            astro_sign = "scorpio";
        }
        else if (month == "november"){
            if (day < 22)
            astro_sign = "scorpio";
            else
            astro_sign = "sagittarius";
        }
        Console.WriteLine(astro_sign);
    }
    // 测试代码
    public static void Main ()
    {
        int day = 19;
        string month = "may";
        zodiac_sign(day, month);
    }
}

输出:

Taurus