gpt4 book ai didi

python-3.x - 导入变量未定义

转载 作者:行者123 更新时间:2023-12-03 04:32:58 24 4
gpt4 key购买 nike

目前正在尝试将我的代码从“原始程序”导入到“导入”中,该代码独立工作正常。我收到错误“日期未定义”。我认为该错误与全局变量有关。我知道这一点,并花了一些时间尝试自己解决这个问题,但无济于事。任何帮助表示赞赏:)

 **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)

最佳答案

删除导入命令从 libHWDate 导入 validDate

关于python-3.x - 导入变量未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47117318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com