Advertisement
nikolask

CS50P - PSET8_seasons_1.py

Sep 12th, 2023
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | Source Code | 0 0
  1. # https://cs50.harvard.edu/python/2022/psets/8/seasons/
  2.  
  3. import inflect, sys
  4. from datetime import date
  5.  
  6.  
  7. def main():
  8.     p = inflect.engine()
  9.     output = p.number_to_words(find_minutes(get_dob()), andword="")
  10.     print(f"{output} minutes")
  11.  
  12.  
  13. def get_dob():
  14.     # create a list of integers from the "-" splitted date
  15.     dob = list(map(int, input("Date of birth: ").split("-")))
  16.     if not dob:
  17.         raise ValueError
  18.         exit("bye")
  19.     else:
  20.         # return an instanciated date object
  21.         return date(dob[0], dob[1], dob[2])
  22.  
  23.  
  24. def find_minutes(birthday):
  25.     today = date.today()
  26.     timedelta = today - birthday
  27.     return round(timedelta.total_seconds() / 60)
  28.  
  29.  
  30. if __name__ == "__main__":
  31.     main()
  32.  
Tags: CS50P
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement