I want to write a program that first reads in 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).
And the contents of input1.txt are:
aspiration
classified
federation
graduation
millennium
philosophy
quadratics
transcript
wilderness
zoologists
If the input is:
ammoniated
millennium
Here is my code:
f=open('input1.txt')
str1=input()
str2=input()
word_in_file= f.readlines()
for word in word_in_file:
word=word.strip()
if str1<=word<=str2:
print(word)
f.close()
the output is:
aspiration
classified
federation
graduation
millennium
When I tried for another attempt, which I only removes the line word=word.strip()
, my output turned into:
aspiration
classified
federation
graduation
My question is why the last string millennium
is no longer included in the output?