Ask Question
9 July, 16:03

Write a program that first reads in the name of an input file, followed by two strings representing the lower and upper bounds of a search range. The file should be read using the file. readlines () method. The input file contains a list of alphabetical, ten-letter strings, each on a separate line. Your program should output all strings from the list that are within that range (inclusive of the bounds).

+3
Answers (2)
  1. 9 July, 17:19
    0
    filepath = 'Iliad. txt'

    start = 'sometxtstart'

    end = 'sometxtend'

    apending = False

    out = ""

    with open (filepath) as fp:

    line = fp. readline ()

    while line:

    txt = line. strip ()

    if (txt = = end):

    apending = False

    if (apending):

    out+=txt + '/n'

    if (txt = = start):

    apending = True

    line = fp. readline ()

    print (out)
  2. 9 July, 17:21
    0
    def func (filename, lower, upper):

    file = open (filename, 'r'). readlines ()

    for i in range (int (lower), int (upper)):

    print (file[i]. rstrip ())

    func ('strings','2','4')

    Explanation:

    file is provided below, name: strings in text format

    appleelppa

    banananana

    cattaccatt

    dogdogdogd

    elephanttn

    froggorffr

    goattaoggo

    horseesroh

    illiterate

    jumppmujju
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that first reads in the name of an input file, followed by two strings representing the lower and upper bounds of a search ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers