#coding:utf-8
#题目:输入某年某月某日,判断这一天是这一年的第几天?
data = input('输入年月份,格式2016-05-12:')
#字符串切割
s = data.split("-")#以-为标志切割
if(len(s == 3)):
#赋值
year = int(s[0])
mon = s[1]
day = s[2]
print (mon)
# python没有switch case 用字典方式
else:
print('输入有误')
da={'1':0,'2':31,'3':59,'4':90,'5':120,'6':151,'7':181,'8':212,'9':243,'10':273,'11':304,'12':334}
def f(x):
return da.get(x)
sum = int(f(mon)) + int(day)
if(year %400 == 0 or (year %4 == 0 and year %100 != 0)):
if(int(mon) >= 3):
sum += 1
print(sum)
运行然后报错
Traceback (most recent call last):
File "G:/小甲鱼教程/算法题/求第几天.py", line 8, in
if(len(s == 3)):
Type Error: object of type 'bool' has no len()