Coder Social home page Coder Social logo

clarencesarmiento / cs50p-final-project Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 32 KB

A Final Requirement for CS50's Introduction to Programming with Python.

Python 100.00%
error-handling programming python python-programming unit-testing cs50 cs50p cs50project

cs50p-final-project's Introduction

Age Calculator

Description:

This program prompts the user for date of birth as an input in Month Day, Year format, and prints out the calculated age and days before their birthday.

How the Program Works?

The Program utilizes the python built-in library Datetime1 and import date object. To acquire the current local date, .today() class method from date was used which has .day, .month, and .year instance attributes.

The Program also utilizes the python built-in library re2 or regular expression. This library was used to check the format of the inputted birthdate and extracts the neccesarry data.

To calculate the age, subtract the birthyear from the current year.

The calculations of the age are based on the following factors:

  1. If the birthmonth is greater than today's month, this means that the user has not yet celebrated his/her birthday (Example: Birthday is on October[10] and today's month is August[08]). Decrement 1 on age.
  2. If the birthmonth and today's month is equal, check if the birthday is greater than today's day. This means that the user has not yet celebrated his/her birhtday (Example: Birthday is on August 25 and today's day is August 17). Decrement 1 on age.

To calculate the days before birthdate, subtract today's date from the birthdate in current year (Example: 2023, 10, 20 - 2023, 08, 19).

  1. If the birthday in current year is less than today's date (Example: Birthdate 2023, 02, 11; Today's date 2023, 08, 19) then, increment 1 to the birthyear. This will replace to 2024, 02, 11 - 2023, 08, 19.

TODO:

Download

Download the Repository through Clone Repository or Download Zip

git clone https://github.com/clarencesarmiento/CS50P-Final-Project.git

Installation

After download, go to cmd and navigate to the project folder directory.

cd CS50P-Final-Project

Use pip to install needed libraries.

$ pip install -r requirements.txt

Usage

Run the program python script project.py with python.

python project.py

Test the program python script test_project.py with pytest.

pytest test_project.py

After successfully running the program, it will prompt for some birthdate. Enter the birthdate following the given format Month Day, Year.

Input Image

The Program output will be like this:

Output Image

Note

The program is case-insensitive.

Important

Do not forget the comma , between the day and year of the birthdate.

References

Footnotes

  1. Datetime library

  2. re library

cs50p-final-project's People

Contributors

clarencesarmiento avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

pejir

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.