目前正尝试从"原始程序"导入我的代码这是独立工作到"导入"。我收到错误"日期未定义"。我假设错误与全局变量有关。我知道这一点,并花了一些时间试图自己解决这个问题无济于事。任何帮助表示赞赏:)
**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)
答案 0 :(得分:3)
删除导入命令 来自libHWDate import validDate