尝试打印出现字符串的行号

时间:2019-10-24 21:15:38

标签: python-3.x jupyter-notebook

我正在分析布鲁克林99的一集,并且有一个问题必须打印要打印字符串“ like and eggplant”的行号。

我正在使用jupyter笔记本,运行问题时,没有打印错误消息,但没有给出行。

感谢您的帮助。


f = open(r'C:\Users\bubba\Downloads\B99_episode_.txt', 'r')
print(f)

# Choosing TERRY 

# Initialising the value of count as -1 because it appears in the cast list 

count = -1

terry_in_f = f.readlines()
for line in terry_in_f:
    if 'TERRY' in line:
        count = count + 1 
print(count)

f.seek(0)

for index, line in enumerate(f):
    if line.lower() == 'like an eggplant':
        print(line)

0 个答案:

没有答案