我是python的新手,正在寻找一些帮助来创建允许用户输入自定义日期范围的函数。到目前为止,我已经完成了我的工作,但似乎无法使其正常工作。
def customised_range():
'''Allows the user to create a customised date range'''
print("{:=^40}".format("Date Menu"))
start = input("Please enter a start date (DD-MM-YYYY): ")
base = date.datetime.strptime(start, "%02d-%02d-%04d")
if base > date.datetime.now():
print("Invalid input(Future Date entered)! Please try again.")
customised_range()
end_date = input("Please enter an end date (DD-MM-YYYY): "
end = data.datetime.strptime(end_date, "%02d-%02d-%04d")
if end > date.datetime.now() or end < base:
print("Invalid input, Please try again!")
customised_range()