Python Forum

Full Version: for some reason this isnt working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import datetime

def inputYear(msg, errmsg, l, h):
    done = 0
    while (not done):
        try:
            ans = input(msg)
            global year
            year = int(ans)
            if (year < l) or (year > h):
                print(errmsg)
            else:
                done = 1
                return year
        except:
            print(errmsg)

def inputMonth(msg, errmsg, l, h):
    done = 0
    while (not done):
        try:
            ans = input(msg)
            month = int(ans)
            if (month < l) or (month > h):
                print(errmsg)
            else:
                done = 1
                return month
        except:
            print(errmsg)

def inputDay(msg, errmsg, l, h):
    done = 0
    while (not done):
        try:
            ans = input(msg)
            day = int(ans)
            if (day < l) or (day > h):
                print(errmsg)
            elif month == (4,6,9,11):
                if day == 30:
                    print(errmsg)
            elif month == 2:
                if year % 4 >= 1 and day >= 29:
                    print(errmsg)
            else:
                done = 1
                return day
        except:
            print(errmsg)

print(inputYear('Please input year(1-9999)', 'Please input a valid year', 1, 9999))
print(inputMonth('Please input month(1-12)', 'Please input a valid month', 1, 12))
print(inputDay('Please input day(1-31)', 'Please input a valid day', 1, 31))
this isnt working is not very descriptive...
It does not produce desired result? It ends with error? In case of error - post the full traceback in error tags..
does this
print(errmsg)
What is the desired result? Some sort of date validation? Is there reason that it is done separately for year, month and day?

I observed that datetime is imported but not used.