老冰棍e 发表于 2020-3-20 22:31:44

python 课后作业第18讲

def findstr(destr,substr):
    count = 0
    length = len(destr)
    if substr not in destr:
      print('未找到相应字符串')
    else:
      for each1 in range(length - 1):
            if destr == substr:      
                if destr == substr:
                  conut += 1
                  
      print('子字符串共出%d' % count)
destr = input('请输入目标')
substr = input('请输入两个字符串')
findstr(destr,substr)

Traceback (most recent call last):
File "C:/Users/11510/Desktop/aa.py", line 15, in <module>
    findstr(destr,substr)
File "C:/Users/11510/Desktop/aa.py", line 10, in findstr
    conut += 1
UnboundLocalError: local variable 'conut' referenced before assignment
问一下在运行时为什么会报错   我是对着答案打的 答案能运行 我这个就报错。。。。。。。。。。。{:10_266:}

qiuyouzhi 发表于 2020-3-20 22:32:58

拼写错误。。。
count 写成 conut

LYF511 发表于 2020-3-21 09:14:17

是count,不是conut

lixiangyv 发表于 2020-3-21 10:18:23

你的拼写有问题,
应该是 count ,而不是 conut 。
在函数里没定义就是用就会报这个错误。

aaron.yang 发表于 2020-3-21 12:18:01

拼写错误,是count,不是conut
页: [1]
查看完整版本: python 课后作业第18讲