I am trying to write a program that allows a user to continue to type out strings until an empty string is entered. Then the program sorts through the strings and prints the string in depending order ( lexicographically ).
The string output should look something like this.
enter a string: the tree is nice and brown
output: tree the nice is brown and
I have tried to implement this code for myself however I have ran into a problem where it prints the code multiple times. see bellow code.
Enter string: the tree is nice and brown
Output: tree Output: the Output: nice Output: is Output: brown Output: and Enter string:
how can I fix my code to remove the Output: that continues to be printed after each word in the string. And also make the final enter new string print on a new line.
See bellow my final code.
s=input("Enter string: ")
while s!="":
a=s.lower()
b=a.split()
b.sort(reverse=True)
for i in b:
answer=""
answer+=i
print("Output: ", answer, end=" ")
s=input("Enter string: ")
>Solution :
Does this fix the problem.
s=input("Enter string: ")
while s!="":
a=s.lower()
b=a.split()
b.sort(reverse=True)
output = ("OUTPUT: \n" + " ".join(b)
print(output)
s=input("Enter string: ")