i need help with this script
if it is in a different order in the text of the document then the picture will give a wrong result
input 27: 1: 1
and script da output
27: 1: 10
which is wrong would anyone help and modify the script? Thank you
if i have the file in a different order then the wrong result need to always find the result of what will be the input
userinput = input("Enter Book, Chapter, Verse:")
file = open("kjv.txt")
lines = file.readlines()
for line in lines:
if userinput in line:
print(line)
break
file.close()
kjv.txt is bible text format
27:1:1 The Revelation of Jesus Christ which God gave him so that his servants might have knowledge of the things which will quickly take place: and he sent and made it clear by his angel to his servant John;
CodePudding user response:
userinput in line
looks for the input string as a substring anywhere in the line, it doesn't check for word boundaries.
Since the verse information is always the first word of the line, split the line and check if the first element is equal to the input.
userinput = input("Enter Book, Chapter, Verse:")
with open("kjv.txt") as file:
for line in file:
words = line.split()
if len(words) > 0 and userinput == words[0]:
print(line)
break