Question

Write a PYTHON program that reads in three strings and sorts them lexicographically. Do NOT user...

  1. Write a PYTHON program that reads in three strings and sorts them lexicographically. Do NOT user the sort function.

Enter string 1: Charlie

Enter string 2: Able

Enter string 3: Baker

Able

Baker

Charlie

  1. Your code with comments
  2. A screenshot of the execution

Test Cases:

                  Able, Baker, Charlie

                  Baker, Charlie, Able

                  Charlie, Able, Baker

                  Able, Charlie, Baker

                  Baker, Able, Charlie

                  Charlie, Baker, Able

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Source Code in Python:

#inputs
s1=input("Enter string 1: ")
s2=input("Enter string 2: ")
s3=input("Enter string 3: ")
print("Strings after sorting :")
if s1.lower()<=s2.lower() and s1.lower()<=s3.lower(): #if s1 is lexigraphically lower than the other strings
print(s1)
if(s2.lower()<=s3.lower()): #if s2 is lexigraphically lower than s3
print(s2)
print(s3)
else: #if s3 is lexigraphically lower than s2
print(s3)
print(s2)
elif s2.lower()<=s1.lower() and s2.lower()<=s3.lower(): #if s2 is lexigraphically lower than the other strings
print(s2)
if(s1.lower()<=s3.lower()): #if s1 is lexigraphically lower than s3
print(s1)
print(s3)
else: #if s3 is lexigraphically lower than s1
print(s3)
print(s1)
else: #if s3 is lexigraphically lower than the other strings
print(s3)
if(s1.lower()<=s2.lower()): #if s1 is lexigraphically lower than s2
print(s1)
print(s2)
else: #if s2 is lexigraphically lower than s1
print(s2)
print(s1)

Output:

Add a comment
Know the answer?
Add Answer to:
Write a PYTHON program that reads in three strings and sorts them lexicographically. Do NOT user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA CODE FOR BEGINNERS!! Write a program that reads three strings from the keyboard. Although the...

    JAVA CODE FOR BEGINNERS!! Write a program that reads three strings from the keyboard. Although the strings are in no particular order, display the string that would be second if they were arranged lexicographically.

  • Write a PYTHON program that reads a file (prompt user for the input file name) containing...

    Write a PYTHON program that reads a file (prompt user for the input file name) containing two columns of floating-point numbers (Use split). Print the average of each column. Use the following data forthe input file: 1   0.5 2   0.5 3   0.5 4   0.5 The output should be:    The averages are 2.50 and 0.5. a)   Your code with comments b)   A screenshot of the execution Version 3.7.2

  • Python code Write a program that will ask the user to input two strings, assign the...

    Python code Write a program that will ask the user to input two strings, assign the strings to variables m and n If the first or second string is less than 10 characters, the program must output a warning message that the string is too short The program must join the strings m and n with the join function The output must be displayed. Please name the program and provide at least one code comment (10)

  • In Python, write a program that reads a text file that is provided by the user...

    In Python, write a program that reads a text file that is provided by the user - ensure that the file exists before processing it! The file might be in a different directory, so be sure to test you logic - the user will provide the absolute path to the file if it is not in the same directory as the Python script! You should then ask the user for what string to search for in the file. Your program...

  • In python please. Write a program that reads whitespace delimited strings (words) and an integer (freq)....

    In python please. Write a program that reads whitespace delimited strings (words) and an integer (freq). Then, the program outputs the strings from words that have a frequency equal to freq in a case insensitive manner. Your specific task is to write a function wordsOfFreqency(words, freq), which will return a list of strings (in the order in which they appear in the original list) that have a frequency same as the function parameter freq. The parameter words to the function...

  • Must be written in C++ Display results and comments Write a program that sorts a vector...

    Must be written in C++ Display results and comments Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific name using binary search. To do that, you need to write three functions: 1. void selSort (vector <string> & v): sorts the vector using selection sort 2. void display (const vector <string> & v): displays the vector contents 3. int binSearch (const vector <string> & v, string key): searches...

  • b) Write a program that takes three strings from the user, compare the strings, and output...

    b) Write a program that takes three strings from the user, compare the strings, and output them concatenated (as one string). The concatenated string should contain the three strings from shorter to longer.

  • (Count the occurrences of each keyword) Write a python program that reads in a Python source...

    (Count the occurrences of each keyword) Write a python program that reads in a Python source code file and counts the occurrence of each keyword in the file. Your program should prompt the user to enter the Python source code filename.

  • Intro to Programming and Logic: Python 2, Chapter 8 – Strings (so far have learned the...

    Intro to Programming and Logic: Python 2, Chapter 8 – Strings (so far have learned the way of a program, variables, expressions, statements, functions, interface design, conditional, recursion and iteration) Write a program that takes a string as a parameter. It will analyze the string and return True if it is a valid float number. It will return False if it is not a valid float value. Your function should return True in any of these cases: 0.17, .17, 5.27,...

  • ***PLEASE USE C++ LANGUAGE*** Binary Search of Strings 1. Write a version of the selection sort...

    ***PLEASE USE C++ LANGUAGE*** Binary Search of Strings 1. Write a version of the selection sort algorithm presented in the unit, which is used to search a list of strings. 2. Write a version of the binary search algorithm presented in the unit, which is used to search a list of strings. (Use the selection sort that you designed above to sort the list of strings.) 3. Create a test program that primes the list with a set of strings,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT