B. Lowest: Write a program called lowest.py which asks the user to enter three words and printsout the lowest word alphabetically. Your program must use if statements and what we have coveredso far in this class (not advanced data structures and algorithms such asdictionaries, which we have not covered yet). For example, if the user enters:lists, tuples, sets, andfrankbobtomYour program outputs:bob

Question
Asked Sep 4, 2019
4 views

Please help me solve this problem 

 

B. Lowest: Write a program called lowest.py which asks the user to enter three words and prints
out the lowest word alphabetically. Your program must use if statements and what we have covered
so far in this class (not advanced data structures and algorithms such as
dictionaries, which we have not covered yet). For example, if the user enters:
lists, tuples, sets, and
frank
bob
tom
Your program outputs:
bob
help_outline

Image Transcriptionclose

B. Lowest: Write a program called lowest.py which asks the user to enter three words and prints out the lowest word alphabetically. Your program must use if statements and what we have covered so far in this class (not advanced data structures and algorithms such as dictionaries, which we have not covered yet). For example, if the user enters: lists, tuples, sets, and frank bob tom Your program outputs: bob

fullscreen
check_circle

Expert Answer

Step 1

Run the below program in “Python 3” and name the corresponding files as “lowest.py”.In this program, two functions are used such as “sort_words()” to sort the words and “main()” function to read the three input words.

Step 2

'''Function sort_word()to sort the words aplhabetically using nested if statement'''

def sort_words(str1,str2,str3):

    #Assign the "str1" to "lowest_word"

    lowest_word=str1

    #Check if the "lowest_word" is greater than "str2"

    if(lowest_word>str2):

         #Assign the "str2" to "lowest_word"

        lowest_word=str2

    #Check if the "lowest_word" is greater than "str3"

    if (lowest_word>str3):

        #Assign the "str3" to "lowest_word"

        lowest_word=str3

    #return the lowest_word

    return lowest_word

 

#main function

def main():

    #Read the three words from user

    s1=input("Enter a word:")

    s2=input("Enter a word:")

    s3=input("Enter a word:")

    #Call the function sort_words() to sort the words

    lowest_word=sort_words(s1,s2,s3)

    #Print the lowest_word

    print("lowest word:",lowest_word)

#Call the main() function

main()

Step 3
help_outline

Image Transcriptionclose

Function sort_word () to sort the words aplhabetically using nested if statement'' def sort words (stri, str2, str3) #Assign the "str1" to "lowest word" lowest word-strl #Check if the "lowest word" is greater than "str2" if (lowest word>str2) #Assign the "str2" to "lowest word" lowest word=str2 #Check if the "lowest word"is greater than "str3" if (lowest word>str3): #Assign the "str3" to "lowest word" lowest word-str3 #return the lowest word return lowest word #main function def main () #Read the three words from user s1-input ("Enter a word:") 32-input ("Enter a word:") 33-input ("Enter a word:") #Call the function sort words to sort the words lowest word- sort words (s1,s2,s3) #Print the lowest word print ("lowest word:", lowest word) #Call the main ( function main

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Python

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: what are the popular cost estimation techniques used for software cost estimation

A: Software cost estimation: Software cost estimation is a method or process that can help IT professio...

question_answer

Q: what is a future embedded computer mean?

A: Embedded computersAn embedded computer is a computer that is designed to do a specific task. An embe...

question_answer

Q: Write a complete C++ program that randomly generates 20 integers between the rangeof 1 to 50 and sto...

A: Solution:Given data,The C++ code to generate the 20 random numbers with the range from “1” to “50”, ...

question_answer

Q: This is for python For this assignment, you will write a program to simulate a payroll application. ...

A: Instruction for the given program:Add the given Node class in the python file Node.py.Add the given ...

question_answer

Q: Note: Numbers greater then 3,999 require symbols with lines over letters. We can't use these, so use...

A: Note: The given python program has been compiled and executed in "repl.it" online complier.Screensho...

question_answer

Q: Write a program that coverts a zip code to a bar code. The bar codes use large and small bars. We wi...

A: Solution:#Define the functiondef checksum(zip):    #Declare the empty variable    sum = 0    #Loop e...

question_answer

Q: getRandomLib.h: // This library provides a few helpful functions to return random values// * getRand...

A: Program Instructions:Include the necessary header files.Print hello message and as for a response.De...

question_answer

Q: Are climate change models accurate?

A: DescriptionClimate Models are basically an add-on of weather forecasting models. But these models ar...

question_answer

Q: Show a derivation tree for w = aaabbaaa using the grammar in Example 5.1. EXAMPLE 5.1 The grammar G ...

A: Solution:Given that,w = aaabbaaa