Age-Calculator Program This is a code to calculate somebody's age. It takes 2 inputs: 


A specific date (to calculate your age at a specific time or the current time).
The birth date.




print('''# This is Age Calculator Program.
# This program is written by Mahmoud Naguib and it will be improved.
# You can contact me at : https://www.facebook.com/naguibarea
--------------------------------------------------------------------''')
import re

while True:
    spefic_date = input('Enter a spefic date (like this format: day/month/year): ')
    birth_date = input('Enter the birth date (like this format: day/month/year): ')
    print('--------------------------------------------------------------------')
    # This line makes sure that the user's inputs are correct
    # if not it will print a message and the user will enter them again.
    if re.search(r'\d{1,2}/\d{1,2}/\d{4}', spefic_date) is None or re.search(r'\d{1,2}/\d{1,2}/\d{4}', birth_date) is None:
        print('You have entered a wrong format! ')
        print('--------------------------------------------------------------------')
        continue
    # This will convert the user's input into lists to use them in assigning values.
    spefic_date = spefic_date.split('/')
    birth_date = birth_date.split('/')

    # This line assigns spefic year's, month's and day's values.
    spefic_year, spefic_month, spefic_day = int(spefic_date[2]), int(spefic_date[1]), int(spefic_date[0])
    # This line specifies birth year's, month's and day's values.
    birth_year, birth_month, birth_day = int(birth_date[2]), int(birth_date[1]), int(birth_date[0])
    # These lines are for math rules.
    if spefic_day &lt; birth_day:
        spefic_day += 30
        spefic_month -= 1
    if spefic_month &lt; birth_month:
        spefic_month += 12
        spefic_year -= 1
    # These lines calculate years, months and days.  
    year = str(spefic_year - birth_year) + ' years, '
    month = str(spefic_month - birth_month) + ' months and '
    day = str(spefic_day - birth_day) + ' days. '
    # These lines are for grammar rules.
    if spefic_year - birth_year &lt; 2:
        year = year.replace('years', 'year')
    if spefic_month - birth_month &lt; 2:
        month = month.replace('months', 'month')
    if spefic_day - birth_day &lt; 2:
        day = day.replace('days', 'day')
    print('Your age is: ' + year + month + day)
    print('--------------------------------------------------------------------')
I don't have much time for the review so I'll focus on regular expressions for the time being.

About re


You should probably be using match instead of search because you want the pattern to be at the beginning of the string. Read more
If you are re-using the same regexp multiple times like you are doing here, it might be worth compile-ing it.
You could use the logic used for matching to split your result as well. If you do so, you do not need to change things in multiple places if the format changes;


Like this :

&gt;&gt;&gt; date = "14/07/1789"
&gt;&gt;&gt; m = re.match(r'(\d{1,2})/(\d{1,2})/(\d{4})', date)
&gt;&gt;&gt; m.groups()
('14', '07', '1789')



Even better, you could use named elements. If the format changes (because your code is used in a different country where dates have a different format for instance), only the regexp will change, the code will still be ok because it will be accessing elements by their name and not by their position.


Like this :

&gt;&gt;&gt; date = "14/07/1789"
&gt;&gt;&gt; m = re.match(r'(?P&lt;day&gt;\d{1,2})/(?P&lt;month&gt;\d{1,2})/(?P&lt;year&gt;\d{4})', date)
&gt;&gt;&gt; m.groups()
('14', '07', '1789')
&gt;&gt;&gt; m.groupdict()
{'month': '07', 'day': '14', 'year': '1789'}


Also, the whole logic converting strings to dates (or to triples (day, month, year)) could be extracted in a function on its own.

You might also decide that you want to reuse already existing tools for this such as datetime.strptime

Better user experience

When I input 2 dates which is usually quite painful, I'd rather have my program to fail if the first date is incorrect rather than having to input the second date to know it.