Program to display Astrological Sign or Zodiac Sign for given Date of Birth

Making the Astrological Sign Known

We can move on to determining the user's astrological sign once we have their date of birth. The provided date will be compared with predefined date ranges for each zodiac sign using programming logic.

For instance, we can infer that the user is an Aries if their birthdate falls between March 21 and April 19. We can accurately ascertain the astrological sign for any given date of birth by using a similar line of reasoning for the remaining signs and date ranges.

Understanding Astrological Signs

There are basically 12 sun signs which are the following:

  • Aries (March 21 - April 19)
  • Taurus (April 20 - May 20)
  • Gemini (May 21 - June 20)
  • Cancer (June 21 - July 22)
  • Leo (July 23 - August 22)
  • Virgo (August 23 - September 22)
  • Libra (September 23 - October 22)
  • Scorpio (October 23 - November 21)
  • Sagittarius (November 22 - December 21)
  • Capricorn (December 22 - January 19)
  • Aquarius (January 20 - February 18)
  • Pisces (February 19 - March 20)

Python Date Manipulation Libraries

We will make use of Python's strength and its extensive ecosystem of libraries to build our programme. For our task, these two libraries are crucial:

Python classes for manipulating dates and times are provided by this library.

With the help of the pytz library, working with time zones enables precise calculations.

Before starting the programme, make sure these libraries are installed.

Python code:

Output:

Taurus

The star_sign function is called with the parameters day = 19 and month = "may" in the provided code to test its functionality.

Code:

This code here uses the date as input and determines the astrological sign on the basis of the dates assigned to the signs in scriptures.






Latest Courses