This is a python 3 program, In this program, it is supposed to open a file and c
ID: 3746995 • Letter: T
Question
This is a python 3 program,
In this program, it is supposed to open a file and create a list of each line and then create a dictionary where the fist index of each line is the key the rest are the values. It then prompts the user to enter a word which is supposed to be a key and it would create a list of what is supposed to be its stress syllables that make up a rhyme. I’m having difficulty in trying to check the other keys in the dictionary have those same stress syllables at the end of the its list and print it out.
Here is the file that im using:
and this is an example of what should be the result:
- def reads_file: file- input( f open(file).readlines word_list for words in f word L1st.append words.splito) return word_list -def create dict(word list): rhyme_words- rhyme_words-fitems [0]: items [1:] for items in word_list return rhyme_words - def choose_word(rhyme_words): word_selcted- input('select word to rhyme: .upperO for i in rhyme_words: if i word_selcted: phoneme -rhyme_words[i] for char in range( Lencphoneme)): word phoneme [char] if wordr-11 '1' scheme-phoneme[char:] #if a key has an entire list that is identical to the one given by the input it shouldnt print it # it should only print if 'scheme' is the same at the end of the word print(scheme) printO return scheme s Search Stack Data ExceptionsDebug I/O Python Shell Messages os Commands Ignore this Options Debug I/O (stdin, stdout, stderr) appears below select word to rhyme: chili C'IH1', 'L', "IY0']Explanation / Answer
I have not changed any other functions. This is the modified version of your choose_word function that returns a list of all the rhyming words.
def choose_word(rhyme_words):
word_selected = input('select word to rhyme: ').upper()
for i in rhyme_words:
if i == word_selected:
phoneme = rhyme_words[i]
for char in range(len(phoneme)):
word = phoneme[char]
if word[-1] == '1':
scheme = phoneme[char:]
# Make a list of rhyming words
rhyming = []
# start to check the dictionary for rhyming words
for i in rhyme_words:
# phoneme1 stores the phoneme of
# current word that is being investigated
phoneme1 = rhyme_words[i]
for char in range(len(phoneme1)):
word = phoneme1[char]
if word[-1] == '1':
# scheme1 stores the scheme of
# current word that is investigated
scheme1 = phoneme1[char:]
# if you get semilar scheme and
# it is not exactly same to the selected word
if scheme == scheme1 and phoneme != phoneme1:
rhyming.append(i)
return rhyming
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.