# 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
4 views

check_circle

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

### Want to see the full answer?

See Solution

#### 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