張芝瑜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('張芝瑜輸入搜尋關鍵詞: ')
n = 0
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. 1113.商業軟體,Typescript,神力女超人!https://zzy317.blogspot.com/2026/11/typescriptjavascripttetris.html
    五角型計算機。https://zzy317.blogspot.com/2026/11/htmlcssjavascript.html
    商業軟體期中考。data資料...英文一定要正確。
    https://zzy317.blogspot.com/2026/10/excelandorcountcountifindirect.htmlhttps://zzy317.blogspot.com/2026/11/excelformulas.html
    程式設計期中考,完美!https://zzy317.blogspot.com/2026/11/htmlcssjavascriptpython.html
    https://zzy317.blogspot.com/2026/10/pythoninputfind-1.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

張芝瑜w3schools字串str串列list集合set字典dict元組tuple

張芝瑜EXCEL名稱方塊,AND,OR,COUNT,COUNTIF,INDIRECT間接定址