Question

Please complete the following: Write a Python script to do the following: 1. Ask the use to enter several sentences, one at a

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

# Declares a list to store sentences sentences = [] sen = print(Enter sentences. Blank statement to terminate.) # Loops til# Loops till number of words, and extracts each word for wo in words: # Checks if current word in not available in the dicton

# Declares a list to store sentences
sentences = []

print("Enter sentences. Blank statement to terminate.")
# Loops till empty sentence entered by the user
while True:
# Accepts a sentence
sen = input("Enter a sentence: ")
# Checks if the sentence entered by the user is not empty
if sen:
# Adds the sentence at the end of the sentences list
sentences.append(sen)
# Otherwise empty sentence
else:
# stop the loop
break

# Declartes a list to store words
words = []
# Loops till number of sentences and extracts each sentence
for sen in sentences:
# Converts the current sentence to lower case
# then split it with space
wo = sen.lower().split()
# Loops till number of words in current sentences
for w in wo:
# Adds the current word at the end of the words list
words.append(w)

# Declares a dictornary to store each word frequency
wordFrequency = {}

# Loops till number of words, and extracts each word
for wo in words:
# Checks if current word in not available in the dictonary
if wo not in wordFrequency:
# Counts number of times current word wo available
# in the list words
# Stores the number in the dictionary key wo as word
wordFrequency[wo] = words.count(wo)

print("Frequency of words")
# Loops till end of the dictionay and extracts each key
for wo in wordFrequency:
# Displays the key as word and value as frequency
print(wo, ": ", wordFrequency[wo])

Sample Output:

Enter sentences. Blank statement to terminate.
Enter a sentence: The house of thunder.
Enter a sentence: The top of the list.
Enter a sentence:
Frequency of words
the : 3
house : 1
of : 2
thunder. : 1
top : 1
list. : 1

Add a comment
Know the answer?
Add Answer to:
Please complete the following: Write a Python script to do the following: 1. Ask the use...
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
  • This program is in python and thanks fro whoever help me. In this program, you will...

    This program is in python and thanks fro whoever help me. In this program, you will build an English to Hmong translator program. Hmong is a language widely spoken by most Southeast Asian living in the twin cities. The program lets the user type in a sentence in English and then translate it to a Hmong sentence. The program does not care about grammar or punctuation marks. That means your program should remove punctuation marks from the English words before...

  • Write program and programmer information as comments at the top of the script. Create a text...

    Write program and programmer information as comments at the top of the script. Create a text file called words.txt and include at least 20 English dictionary-based words in your folder. Program must read the list of words from the file into list data structure. Program chooses a random word from the list and starts asking player to guess the word one character at a time until player wins or runs out of predefined no. of tries. Game continues until the...

  • Exercise 1 - Create a List to Sum Values Write a python script that sums the...

    Exercise 1 - Create a List to Sum Values Write a python script that sums the values in a list called add_list that contains the following values: (10, 2, -4, 8). Make sure you include a for loop when iterating through the list to sum the values. Take screenshots of the code and output. Exercise 2 – Create a Dictionary Write a python script that prints a dictionary where the key numbers are 1, 2, 3, 4, and 5 and...

  • PLEASE DO IN JAVA You can use any source for the dictionary or just a few...

    PLEASE DO IN JAVA You can use any source for the dictionary or just a few words are fine! description The purpose of this assignment is to practice with ArrayLists (and hopefully, you'll have some fun). As far as the user knows, play is exactly as it would be for a normal game of hangman, but behind the scenes, the computer cheats by delaying settling on a mystery word for as long as possible, which forces the user to use...

  • In python Count the frequency of each word in a text file. Let the user choose...

    In python Count the frequency of each word in a text file. Let the user choose a filename to read. 1. The program will count the frequency with which each word appears in the text. 2. Words which are the spelled the same but differ by case will be combined. 3. Punctuation should be removed 4. If the file does not exist, use a ‘try-execption’ block to handle the error 5. Output will list the words alphabetically, with the word...

  • PYTHON PLEASE Write a function to censor words from a sentence code: def censor_words(sentence, list_of_words): """...

    PYTHON PLEASE Write a function to censor words from a sentence code: def censor_words(sentence, list_of_words): """ The function takes a sentence and a list of words as input. The output is the sentence after censoring all the matching words in the sentence. Censoring is done by replacing each character in the censored word with a * sign. For example, the sentence "hello yes no", if we censor the word yes, will become "hello *** no" Note: do not censor the...

  • Write a program IN PYTHON that checks the spelling of all words in a file. It...

    Write a program IN PYTHON that checks the spelling of all words in a file. It should read each word of a file and check whether it is contained in a word list. A word list available below, called words.txt. The program should print out all words that it cannot find in the word list. Requirements Your program should implement the follow functions: main() The main function should prompt the user for a path to the dictionary file and a...

  • Python 3.7 Coding assignment This Program should first tell users that this is a word analysis...

    Python 3.7 Coding assignment This Program should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file....

  • Write a script that uses random number generation to create sentences. Use four arrays of strings...

    Write a script that uses random number generation to create sentences. Use four arrays of strings called article, noun, verb and preposition. Create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article and noun. As each word is picked, concatenate it to the previous words in the sentence. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and...

  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

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
ADVERTISEMENT