- Sep 4, 2008
- 653
- 1
- 81
This is not homework.
I am fairly new at python, and I'm working with a script that has a function defined in it. Here is the snippet of code thats giving me an issue:
if not ((iDD > 0 and iDD < 32 and iMM == 1 )
or (iYYYY % 4 == 0 and iYYYY % 400 != 0 and iDD > 0 and iDD < 30 and iMM == 2 )
or (iDD > 0 and iDD < 29 and iMM == 2 )
or (iDD > 0 and iDD < 32 and iMM == 3 )
or (iDD > 0 and iDD < 31 and iMM == 4 )
or (iDD > 0 and iDD < 32 and iMM == 5 )
or (iDD > 0 and iDD < 31 and iMM == 6 )
or (iDD > 0 and iDD < 32 and iMM == 7 )
or (iDD > 0 and iDD < 32 and iMM == 8 )
or (iDD > 0 and iDD < 31 and iMM == 9 )
or (iDD > 0 and iDD < 32 and iMM == 10 )
or (iDD > 0 and iDD < 31 and iMM == 11 )
or (iDD > 0 and iDD < 32 and iMM == 12 )):
sys.stderr.write("invalid day\n")
return -1
Basically its parsing a date, and checking the values in iDD, iMM, and iYYYY to make sure that they form a valid date of a year. I thought that it might have been an earlier piece of code that wasn't storing the variables correctly, but I've confirmed that the variables form valid dates, its just this piece of code isn't working right. The two dates it checks currently store the values:
iDD = 31, iMM = 12, iYYYY = 2002
iDD = 02, iMM = 01, iYYYY = 2001
For the life of me I can't figure out why these values are causing the "invalid day" error to generate every time. Any insight is appreciated!
EDIT: The forum wont recognize white space. Note that the 'if not' and 'or' statements are all indented to the same column, while the 'sys.stderr' and 'return' lines are both indented by one more 'tab.'
I am fairly new at python, and I'm working with a script that has a function defined in it. Here is the snippet of code thats giving me an issue:
if not ((iDD > 0 and iDD < 32 and iMM == 1 )
or (iYYYY % 4 == 0 and iYYYY % 400 != 0 and iDD > 0 and iDD < 30 and iMM == 2 )
or (iDD > 0 and iDD < 29 and iMM == 2 )
or (iDD > 0 and iDD < 32 and iMM == 3 )
or (iDD > 0 and iDD < 31 and iMM == 4 )
or (iDD > 0 and iDD < 32 and iMM == 5 )
or (iDD > 0 and iDD < 31 and iMM == 6 )
or (iDD > 0 and iDD < 32 and iMM == 7 )
or (iDD > 0 and iDD < 32 and iMM == 8 )
or (iDD > 0 and iDD < 31 and iMM == 9 )
or (iDD > 0 and iDD < 32 and iMM == 10 )
or (iDD > 0 and iDD < 31 and iMM == 11 )
or (iDD > 0 and iDD < 32 and iMM == 12 )):
sys.stderr.write("invalid day\n")
return -1
Basically its parsing a date, and checking the values in iDD, iMM, and iYYYY to make sure that they form a valid date of a year. I thought that it might have been an earlier piece of code that wasn't storing the variables correctly, but I've confirmed that the variables form valid dates, its just this piece of code isn't working right. The two dates it checks currently store the values:
iDD = 31, iMM = 12, iYYYY = 2002
iDD = 02, iMM = 01, iYYYY = 2001
For the life of me I can't figure out why these values are causing the "invalid day" error to generate every time. Any insight is appreciated!
EDIT: The forum wont recognize white space. Note that the 'if not' and 'or' statements are all indented to the same column, while the 'sys.stderr' and 'return' lines are both indented by one more 'tab.'
