Ask 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 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. 19 September, 13:31
    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. 19 September, 13:33
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers