|
发表于 2018-4-11 15:28:21
|
显示全部楼层
本帖最后由 shigure_takimi 于 2018-4-11 15:32 编辑
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 200/400
0.5
>>> 800/400
2.0
>>>
因为year/400不可能是int(如上,/ 得到的一定是float)。
有year%400 == 0这种用法,为什么非要用isinstance呢。
- temp = input("please input a 'year':")
- while not temp.isdigit():
- temp = input("Sorry,'year'is wrong,please input a integer: ")
- year = int(temp)
- if (year%4==0 and year%100!=0) or year%400 == 0:
- print(temp + "是闰年")
- else:
- print(temp + '不是闰年!')
复制代码
|
|