I want to iterate through different dates, for instance from 20/08/2015 to 21/09/2016, but I want to be able to run through all the days even if the year is the same. For instance 20/08/2015 to 25/09/2015.
Now if I write this in C, I could just use a for loop and make it so it runs if value of startYear <= value of endYear
, but from all the examples I see online the for loop runs with the range function, which means if I give it the same start and end values it will simply not run.
For example:
startYear=int(raw_input("Starting year (yyyy):"));
endYear=int(raw_input("Ending year (yyyy):"));
for year in range(startYear,endYear,1):
As the input comes from the user I have no control over it. So if startYear
and endYear
are both 2015 I can't make it iterate even once. Note that I can't "cheat" by changing the values of startYear
and endYear
as I am using the variable year for calculations later.
I would love to know:
- Is there a way to run a for loop in Python that checks for lower or equal?
- What is the best way to go about writing this simple iteration?
Thanks