weixin_43749292
Feather
采纳率0%
2018-12-03 07:31

python小白求助!!!!看代码

#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()

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • qq_34355232 DCY7074 3年前

    if(len(s == 3)):
    上面这行代码有错,应该是
    if ( len(s) ==3 ):

    点赞 1 评论 复制链接分享