<?php
$json = <<<JSON
[{"field":"_USERNAME","value":""},
{"field":"_PASSWORD","value":""},
{"field":"_TOKEN","value":""},
{"field":"_CODE","value":"L77H4XD6ZA"},
{"field":"_SUBMITTEDDATE","value":"2017.08.16.01.54"},
{"field":"_SUBMITTEDDATEEXT","value":"2017.08.16.01.54.39.610"},
{"field":"_EDITEDDATE","value":"2017.08.16.01.55"},
{"field":"_SEQUENTIALID","value":"39a1cad9-2582-e711-9477-06c7814985cc"},
{"field":"_COMPLETETYPE","value":"Complete"},
{"field":"_LANGUAGE","value":"en"},
{"field":"_TOTALTIME","value":"12.59"},{"field":"_LINKURL","value":"http%3a%2f%2fsurv.blah.com%2ftest3%3fusr%3dL77H4XD6ZA"},
{"field":"GENDER","value":"TEXT%3aFemale%3bVALUE%3a2"},
{"field":"AGE","value":"TEXT%3a40%2b-%2b44%3bVALUE%3a6"},
{"field":"STATE","value":"TEXT%3aVIC%3bVALUE%3a2"},
{"field":"END_CHC","value":"TEXT%3aComplete%3bVALUE%3a2"},
{"field":"D2H","value":""},
{"field":"D2V","value":""},
{"field":"PCODE","value":""},
{"field":"PSTATE","value":""},
{"field":"PREGION","value":""},
{"field":"STATEREGION","value":""},
{"field":"TEST1","value":""}]
JSON;
$obj = json_decode($json, true);
foreach($obj as $currTuple)
{
echo $currTuple['field'].':'.urldecode($currTuple['value'])."\n";
}
上述代码需要更改什么? 1992,2400,2000 ......它不适用于这些。 我找不到任何其他逻辑。
答案 0 :(得分:2)
你的代码中有很多错误,看起来你错过了%400的操作
def is_leap(year):
leap = False
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0 ):
leap = True
return leap
print(is_leap(2000)) # for 2.7 just print is_leap(2000)
print(is_leap(1000))
print(is_leap(1992))
print(is_leap(2400))
输出
True
False
True
True
答案 1 :(得分:1)
您的功能称为is_leap
。这并不表示与print
有任何关系。所以不要在函数中print
!
def is_leap(year):
return year % 4 == 0
应该足够了。
编辑:我查了维基百科的精确定义:
每年可被4整除的是闰年,除了可以被100整除的年份,但如果它们可以被400整除,那么这些年份就是闰年。
我们的职能是:
def is_leap(year):
return year % 4 == 0 and not (year % 100 == 0) or year % 400 == 0