Come one, come all, bring a word or a line,
This program will sort them and make them all rhyme!
With Python in hand and a file to read,
We’ll find rhyming endings with whimsical speed.
Two letters? Or three? You can pick what you choose,
Just enter your number—there's no way to lose!
If a rhyme can't be found, don’t worry or pout,
Just try a new word and let the fun out!
So type up some verses, both silly and sweet,
And let Seuss-like magic make your rhymes neat.
For fun with your files, there's no better way—
Just use this fine program and rhyme up your day!
In English: This program reads a file you choose and finds which words share rhyming clues! You’ll set how many letters need to match, to help each rhyme group find its batch.
You can search for words that rhyme just right, or see them all displayed in sight. With Python’s help, it won’t take long~! Just run the code and rhyme along!
Specifications
Here are the requirements Cat in the Hat has outlined for his Rhyme Time:
Present the user with four possible commands:
Find all the rhymes in a specified file.
Allow the user to enter a word, and respond with the rhymes in a specified file.
Change how many letters must match at the end of each word to count as a rhyme.
Exit the program.
These commands must be repeated until the user enters 4. For more specific information on each command:
Prompt the user for a file name. If the file exists, read through it line by line, extract the last word from each line,
and group words that end in the same letters (based on the current rhyme length). Display each group of rhyming words,
omitting groups with only one word.
Hint: You'll need to read the file line by line. Use split() to break each line into words, then grab the
last word using [-1]. Don't forget to strip any extra punctuation like commas or periods using a while loop.
After extracting the last word, group them by their last n characters (where n is the rhyme length). Store the rhymes
in a dictionary and display them.
Prompt the user to enter a word, then a file name. Show all words from the file that rhyme with the entered word, based
on the current rhyme length.
Hint: Once you've read the rhymes from the file (from Step 1), the user will enter a word. Use slicing [-n:]
to grab the last n characters from the user's word and compare it with the rhymes in your dictionary. If a
match is found, display the rhyming words; if not, let the user know there are no rhymes.
Prompt the user to enter a number to change the rhyme length (how many letters at the end of each word must match to
count as a rhyme). Update the rhyme length accordingly.
Hint: You'll need to store and update the rhyme length (starting with a default value of 2). When the user wants to
change it, prompt them for a new value. Use input() to get the new length and check if it's a valid number
(e.g., isdigit()). Update the variable that holds the rhyme length.
Print a goodbye message and exit the program.
Hint: When the user selects this option, simply print a farewell message and use return or break
to exit the loop and end the program.
Expected Output
The Cat in the Hat, with a tip of his hat,
Has shown us just what to expect—fancy that!
He laid out the rules in a manner quite clear,
So follow along and bring rhyming cheer!
Oh me, oh my, what do I have here?
A fun program, bringing good cheer!
COMMANDS:
1: Show all the rhymes, have a good time!
2. Have a word? We’ll check where it fits,
3: Change how we rhyme, just for kicks!
4: Exit the rhyme, but come back sometime!
Pick a number, 1 to 4, let's have some fun galore!: 1
Type a file, don't be shy,
give it a name, give it a try!: greenEggsAndHam.txt
Here are your rhymes, all tidy and neat,
Each one a gem, ready to repeat!
--------------------------------------------------
am: {'sam-i-am', 'ham'}
re: {'anywhere', 'are', 'there'}
se: {'mouse', 'house'}
ox: {'box', 'fox'}
ee: {'see', 'tree'}
COMMANDS:
1: Show all the rhymes, have a good time!
2. Have a word? We’ll check where it fits,
3: Change how we rhyme, just for kicks!
4: Exit the rhyme, but come back sometime!
Pick a number, 1 to 4, let's have some fun galore!: 3
Want to tweak the rhyme’s length? Pick a number, show your strength!: 3
COMMANDS:
1: Show all the rhymes, have a good time!
2. Have a word? We’ll check where it fits,
3: Change how we rhyme, just for kicks!
4: Exit the rhyme, but come back sometime!
Pick a number, 1 to 4, let's have some fun galore!: 1
Type a file, don't be shy,
give it a name, give it a try!: greenEggsAndHam.txt
Here are your rhymes, all tidy and neat,
Each one a gem, ready to repeat!
--------------------------------------------------
ere: {'anywhere', 'there'}
use: {'mouse', 'house'}
COMMANDS:
1: Show all the rhymes, have a good time!
2. Have a word? We’ll check where it fits,
3: Change how we rhyme, just for kicks!
4: Exit the rhyme, but come back sometime!
Pick a number, 1 to 4, let's have some fun galore!: 2
Share a word, and you will see, its rhymes will pop up, wild and free!: hound
Type a file, don't be shy,
give it a name, give it a try!: grinch.txt
Here are your rhymes, all tidy and neat,
Each one a gem, ready to repeat!
--------------------------------------------------
{'around', 'found'}
COMMANDS:
1: Show all the rhymes, have a good time!
2. Have a word? We’ll check where it fits,
3: Change how we rhyme, just for kicks!
4: Exit the rhyme, but come back sometime!
Pick a number, 1 to 4, let's have some fun galore!: 4
Goodbye for now, don’t be sad, come back soon, it’ll be rad!
Turning In the Exercise:
You won't need to turn this in, but you should be proud of your work!
For the cherry on top, slot in this header in your file:
# Exercise: Guest Star 2
# File: RhymeTime.py
# Student:
# UT EID:
# Course Name: CS303E
#
# Date Created:
# Description of Program: