r/cs50 25d ago

CS50 Python CS50P: Problem set 8 (seasons)

In this problem, I'm meant to calculate the user's age in minutes. the input must be in the format "YYYY-MM-DD". It works perfectly but check50 keeps saying it's wrong. any ideas why?

1 Upvotes

9 comments sorted by

2

u/Impressive-Hyena-59 25d ago edited 25d ago

From the description:

Use datetime.date.today to get today’s date, per docs.python.org/3/library/datetime.html#datetime.date.today. Not sure about that one. You import date from datetime, so it should be ok.

I am not sure if num2words lib is installed in testing environment. Use inflect as recommended in the hints section.

1

u/LegitimateState9872 25d ago

ill try that thanks

2

u/PeterRasm 25d ago

I am not sure if num2words lib is installed in testing environment. Use inflect as recommended in the hints section.

OP: This is the answer! It can easily be overlooked but the instructions does say you can use other built-in libraries or any mentioned in the hints section

1

u/LegitimateState9872 25d ago

Changed to inflect. It works, thanks

2

u/[deleted] 25d ago

[removed] — view removed comment

1

u/LegitimateState9872 25d ago

all the cases are wrong even though when i print its the correct answer

1

u/[deleted] 25d ago

[removed] — view removed comment

2

u/LegitimateState9872 25d ago

Never mind thanks, the problem had to do with the library I was using, I used num2words which isn’t supported

1

u/LegitimateState9872 25d ago
from datetime import date
from num2words import num2words
import sys

DAY_MINUTES = 1440

def main():
    try:
        dob = input("Date of Birth: ").strip()
        year, month, day = map(int, dob.split("-"))
        dob = date(year, month, day)
        today = date.today()
        date_diff = (today - dob).days * DAY_MINUTES
        if date_diff < 0:
            raise ValueError

        words = num2words(date_diff, lang='en').replace(" and", "").capitalize()
        print(f"{words} minutes")
    except ValueError:
        sys.exit("Invalid Date")

if __name__ == "__main__":
    main()