Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imported Variable not defined

Currently trying to import my code from "Original Program" which is working fine independently into "Import". I am getting the error "Date is not defined". I assume the error is to do with global variables. I am knew to this and have spent some time trying to solve the issue myself to no avail. Any help appreciated :)

 **Original Program**   

def validDate(date, month, day):
    months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
    days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    leapyear = ((date % 4) == 0) and ((date % 100) != 0) or ((date % 4) == 
    0) and ((date % 100) == 0) and ((date % 4000) == 0)
    if leapyear:
    days[1] += 1 
    valid = (day <= days[months.index(month)] and day > 0 and (1753 <= 
    date)) 
    print(valid)

date = int(input("Enter year: "))
month = int(input("Enter month: "))
day = int(input("Enter day: "))

validDate(date, month, day)


**Import**

from libHWDate import validDate

validDate(date, month, day)
like image 359
white Avatar asked Dec 04 '25 17:12

white


1 Answers

remove the import command from libHWDate import validDate

like image 54
Ayoub Benayache Avatar answered Dec 07 '25 06:12

Ayoub Benayache



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!