My code is functional and passes all of the CS50 tests except for the last one. What could be causing this?
This is my main code:
from datetime import timedelta
import inflect
import sys
def main():
print(convert(input("Date of Birth: ")))
def convert(x):
q = inflect.engine()
try:
years, months, days = x.split("-")
years = int(years)
months = int(months)
days = int(days)
dob = date(years, months, days)
today = date.today()
difference = today - dob
min = round(difference.total_seconds()/60)
words = q.number_to_words(min, andword="").capitalize() + " minutes"
return words
except ValueError:
sys.exit("Date must be inputted in YYYY-MM-DD format.")
if __name__ == "__main__":
main()
This is my test code:
from seasons import convert
import pytest
def test_seasons():
assert convert("2022-09-10") == "Five hundred twenty-five thousand, six hundred minutes"
assert convert("2021-09-10") == "One million, fifty-one thousand, two hundred minutes"
with pytest.raises(SystemExit):
convert("sdfs-sd-sd")
with pytest.raises(SystemExit):
convert("20220910")
with pytest.raises(SystemExit):
convert("cat")
And when I run check50 this is what I get:
:) seasons.py and test_seasons.py exist
:) Input of "1999-01-01" yields "Five hundred twenty-five thousand, six hundred minutes" when today is 2000-01-01
:) Input of "2001-01-01" yields "One million, fifty-one thousand, two hundred minutes" when today is 2003-01-01
:) Input of "1995-01-01" yields "Two million, six hundred twenty-nine thousand, four hundred forty minutes" when today is 2000-01-1
:) Input of "2020-06-01" yields "Six million, ninety-two thousand, six hundred forty minutes" when today is 2032-01-01
:) Input of "1998-06-20" yields "Eight hundred six thousand, four hundred minutes" when today is 2000-01-01
:) Input of "February 6th, 1998" prompts program to exit with sys.exit
:( seasons.py passes all checks in test_seasons.py
expected exit code 0, not 1