Python Forum
Need help with getting this voting eligiblity code to work
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with getting this voting eligiblity code to work
#1
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('--------------------------------------------------------------------')
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  my simple code wont work! help! simon12323121 2 2,031 Sep-05-2021, 09:06 AM
Last Post: naughtyCat
  My code does not work as expected (pygame) rohes_kaugummi 1 1,575 Aug-26-2021, 03:13 PM
Last Post: deanhystad
  I wrote a code but it does not work out as expected chinitayao226 2 1,871 Sep-23-2020, 09:14 PM
Last Post: SnowwyWolf
  A program for backing up documents (doesnt work(code is inside)) Richard_SS 4 3,421 Jun-05-2019, 03:47 PM
Last Post: heiner55
  I Can't Get This Sorting Function In This LinkedList Code To Work JayJayOi 10 7,931 Jan-11-2018, 01:14 AM
Last Post: JayJayOi
  Why can't this code work. sexualpanda 2 3,423 Feb-06-2017, 04:03 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020