Python Forum

Full Version: Need help with getting this voting eligiblity code to work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Struggling with how I can get the voting eligibility part at the end to work

import re

while True:
spefic_date = input('Enter todays date (Like this: dd/mm/yyyy): ')
birth_date = input('Enter the birth date (Like this: dd/mm/yyyy): ')
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 < birth_day:
spefic_day += 30
spefic_month -= 1
if spefic_month < 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 < 2:
year = year.replace('years', 'year')
if spefic_month - birth_month < 2:
month = month.replace('months', 'month')
if spefic_day - birth_day < 2:
day = day.replace('days', 'day')
print('Your age is: ' + year + month + day)
if year =< (18)
if month =< (0)
if day =< (0)
print("you are old enough to vote!")
elif year => (18)
elif month > (0)
elif day > (0)
print("you are not old enough to vote!")
print('--------------------------------------------------------------------')
Please repost your code between Python tags so we can see the indentation. See the BBCode link in my signature, below. Also, what exactly is going wrong? If there is an error, please give us the full error text. Otherwise explain why what is happening is not what should be happening.