Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
list=[["capricorn","december 22", "january 19"],
      ["aquarius","january 20", "february 18"],
      ["pisces","february 19", "march 20"],
      ["aries","march 21", "april 19"],
      ["taurus","april 20", "may 20"],
      ["gemini","may 21","june 20"],
      ["cancer","june 21", "july 22"],
      ["leo","jul 23", "august 22"],
      ["virgo","august 23", "september 22"],
      ["libra","september 23", "october 22"],
      ["scorpio","october 23", "november 21"],
      ["sagittarius","november 22", "december 21"]]

Ask the user for an input and then return the zodiac sign if date lies between 2 dates.

What I have tried:

Eg :-If a date lies between december 22 and January 19 then capricorn should be printed
Posted
Updated 4-Sep-22 10:36am
v2
Comments
PIEBALDconsult 18-Aug-22 9:26am    
Use proper DateTime (or equivalent) data types.

1 solution

A datetime object should contain at least 3 parts: year, month and day.

There's several ways to convert string into date. See: https://stackoverflow.com/questions/2803852/python-date-string-to-date-object[^]

For example:
Python
from dateutil import parser
y = 2022
d1 = parser.parse(f"{y} december 22")
d2 = parser.parse(f"{y + 1} january 19")
print(d1, d2)


For date comparison - check this out: Python Compare DateTime - Python Examples[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900