Question: I made a program on Python that asks the user to enter a date and the program will validate the date and format in the
I made a program on Python that asks the user to enter a date and the program will validate the date and format in the proper date format. For example: user enters 12032021 then the program will print 12/03/2021. I need someone to help change the program, so the program will gather the individual values of the month, day, and year instead of the whole date. The program should ask for the 3 values (month, day, year) then use the validate, then print as a date format xx/xx/xxxx. Thank you. (my program below)
def day():
"""This function will get the date from the user"""
day = input("Please enter the day, month, and year with no spaces or dashes ")
day_ok = False
while not day_ok:
day_ok = validate_value(day)
if not day_ok:
day = input("The value was invalid please enter again")
day_ok = validate_value(day)
return day
def validate_value(passed_value):
"""Validate weather or not the value entered is numeric"""
if passed_value:
if passed_value.isnumeric():
return True
else:
return False
else:
return False
def dateformat():
"""This function will format the date in the correct date format"""
date = day()
newdate = ""
if(len(date) == 7):
newdate = date[0] + '/' + date[1:3] + '/' + date[3:8]
else:
newdate = date[:2] + '/' + date[2:4] + '/' + date[4:9]
return newdate
#calls function
print(dateformat())
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
