Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

searching for a verse in the bible

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;

enter image description here

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading