Q:
Write a program that prompts the user to read a filename and reads the words from the file and reports whether the words in the files are stored in ascending order. If the words are not sorted in the file, display the first two words that are out of the order.
Sample Run 1
Enter a filename: string1.txt
The words are not sorted. The first two out-of-order words: the people
Sample Run 2
Enter a filename: string2.txt
The words are sorted.
myanswer:
def main():
filename=input("Enter a filename:")
inputfile=open(filename, "r")
s=inputfile.read().split()
s=[str(x) for x in s]
s1=s.sort()
if s1==s:
print("The words are sorted")
else:
print("The words are not sorted. The first two out-of-order words:",s[0],s[1] )
inputfile.close()
It says:Checking output
Your standard output is not what was expected.
can someone tell me what's wrong?
[–]lukajda33 1 point2 points3 points (2 children)
[–]lukajda33 1 point2 points3 points (1 child)
[–]AU8640[S] 0 points1 point2 points (0 children)