# Search if a word exists in a file.
fs = open("ipt.txt", "r")
search_str = input("Enter string to search : ").strip()
Flag = False
while(True):
Line = fs.readline().strip()
if not Line:
break
if (search_str in Line):
Flag = True
break
if(Flag==True):
print(search_str, "present in file")
else:
print(search_str, "not present in file")
fs.close()
fs = open("ipt.txt", "r")
search_str = input("Enter string to search : ").strip()
Flag = False
while(True):
Line = fs.readline().strip()
if not Line:
break
if (search_str in Line):
Flag = True
break
if(Flag==True):
print(search_str, "present in file")
else:
print(search_str, "not present in file")
fs.close()
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu