呂庭娟python輸入input尋找find沒找到-1

file = open('金融常識.txt','r',encoding='utf-8')
lines = file.readlines()
file.close()
x = input('呂庭娟入搜尋關鍵詞: ')
for line in lines:
 if line.find(x) != -1: print(line,end="")
file = open('金融常識.txt','r',encoding='utf-8')
lines = file.readlines()
file.close()
x = input('呂庭娟入搜尋關鍵詞: ')
for line in lines:
     if line.find(x) != -1: 
        n=n+1
        print(n,' ',line,end='')
 print(F'總共(n)題')
file = open('金融常識.txt','r',encoding='utf-8')
lines = file.readlines()
file.close()
x = input('呂庭娟輸入搜尋關鍵詞: ')
n = 0
for line in lines:
    if x in line:
        n=n+1
        print( n, ' ', line,end='')
print(f'總共{n}題')
file = open('金融常識.txt','r',encoding='utf-8')
reading = file.read()
file.seek(0) #回到檔案的開始
lines = file.readlines()
file.close()
print('read()方法讀共', len(reading), 'readlines()方法讀共', len(lines))
x = input('呂庭娟輸入搜尋關鍵詞: ')
n = 0
for line in lines:
    if x in line:
        n=n+1
        print( n, ' ', line,end='')
print(f'總共{n}題')

留言

  1. 917嵌入網頁有錯誤。https://lutingjuan.blogspot.com/2026/09/excelfindlenleftmidrightpowerunicharuni.html
    商業軟體,要記得修改成正確的呈現。https://lutingjuan.blogspot.com/2026/11/excelformulas.html
    1016商業軟體。https://lutingjuan.blogspot.com/2026/10/excelmatchindexisnumber.html
    程式設計期中考,可以再嵌入影片。https://lutingjuan.blogspot.com/2026/11/htmlcssjavascriptpython.html
    1019. input. https://lutingjuan.blogspot.com/2026/10/pythoninputfind-1.html
    金融常識測驗網頁,順利執行。https://lutingjuan.blogspot.com/2026/10/blog-post.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

呂庭娟w3schools字串str串列list集合set字典dict元組tuple 10月 04, 2026

呂庭娟

呂庭娟雙迴圈