D 2. Use the scarlet.txt file to determine how often does "red" and "scarlet" appear in Sir. Arthur Conan Doyle's "The Study in Scarlet". Implement your algorithm in lab8_p2.py. Display a meaningful output that includes the word counts • Possible extension: Enhance the display by creating a histogram of the word counts. Creativity is highly encouraged! • Possible extension 2: Display the line numbers where the words were found. • Possible extension 3: If you look inside the scarlet.txt file you will see that the word "scarlet" appeared more than one time. The program requires some specific instructions to deal with the situation when that word is followed by a punctuation or it's at the end of the line or even appears in all caps. Update your program to deal with all these unique conditions. Hint: use the find feature (command f) to search for the occurrences of scarlet in the text file. CONSOLE SHELL ********Basic Solution****** The word 'red' appears 5 times in the text file The word 'scarlet' appears 1 times in the text file *****Extension 1****** word1: #**** word2: # ********Extension 2****** Open Desktop The word 'red' appears 5 times in the text file on the following lines: 988, 1419, 1462, 1979, 2249 The word 'scarlet' appears 1 times in the text file on the following lines: 1508 4 lab8_p1.py x lab8_p3.py x words5000.csv x scarlet.txt × lab8_p2.py × × 1 # Problem 2 2 word1 "red" 3 word2 = "scarlet" 5 # Add your code below 6 7 8 9 10 11 12 with open("scarlet.txt", "r") as file: for line in file: words line.strip().split(", ") word1_count= words.count(word1) word2_count= words.count(word2) print (f"The word '{word1}' appears: {word1_count} times") print(f"The word '{word2}' appears: (word2_count} times") CONSOLE SHELL Check Answer Reset to Template Recent Submissions

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

If you could help me with what im doing wrong in this python code. I have opened the file scarlet.txt but for some reason it keeps saying that there are 0 red words and 0 scarlet words. I would really appreciate it

D
2. Use the scarlet.txt file to determine how often does "red"
and "scarlet" appear in Sir. Arthur Conan Doyle's "The
Study in Scarlet". Implement your algorithm in lab8_p2.py.
Display a meaningful output that includes the word counts
• Possible extension: Enhance the display by creating a
histogram of the word counts. Creativity is highly
encouraged!
• Possible extension 2: Display the line numbers where the
words were found.
• Possible extension 3: If you look inside the scarlet.txt file
you will see that the word "scarlet" appeared more than
one time. The program requires some specific instructions
to deal with the situation when that word is followed by a
punctuation or it's at the end of the line or even appears in
all caps. Update your program to deal with all these unique
conditions. Hint: use the find feature (command f) to search
for the occurrences of scarlet in the text file.
CONSOLE SHELL
********Basic Solution******
The word 'red' appears 5 times in the text file
The word 'scarlet' appears 1 times in the text file
*****Extension 1******
word1: #****
word2: #
********Extension 2******
Open Desktop
The word 'red' appears 5 times in the text file on the following lines: 988, 1419,
1462, 1979, 2249
The word 'scarlet' appears 1 times in the text file on the following lines: 1508
4
lab8_p1.py x
lab8_p3.py x words5000.csv x
scarlet.txt ×
lab8_p2.py × ×
1 # Problem 2
2
word1 "red"
3
word2 = "scarlet"
5
# Add your code below
6
7
8
9
10
11
12
with open("scarlet.txt", "r") as file:
for line in file:
words line.strip().split(", ")
word1_count= words.count(word1)
word2_count= words.count(word2)
print (f"The word '{word1}' appears: {word1_count} times")
print(f"The word '{word2}' appears: (word2_count} times")
CONSOLE
SHELL
Check Answer
Reset to Template
Recent Submissions
Transcribed Image Text:D 2. Use the scarlet.txt file to determine how often does "red" and "scarlet" appear in Sir. Arthur Conan Doyle's "The Study in Scarlet". Implement your algorithm in lab8_p2.py. Display a meaningful output that includes the word counts • Possible extension: Enhance the display by creating a histogram of the word counts. Creativity is highly encouraged! • Possible extension 2: Display the line numbers where the words were found. • Possible extension 3: If you look inside the scarlet.txt file you will see that the word "scarlet" appeared more than one time. The program requires some specific instructions to deal with the situation when that word is followed by a punctuation or it's at the end of the line or even appears in all caps. Update your program to deal with all these unique conditions. Hint: use the find feature (command f) to search for the occurrences of scarlet in the text file. CONSOLE SHELL ********Basic Solution****** The word 'red' appears 5 times in the text file The word 'scarlet' appears 1 times in the text file *****Extension 1****** word1: #**** word2: # ********Extension 2****** Open Desktop The word 'red' appears 5 times in the text file on the following lines: 988, 1419, 1462, 1979, 2249 The word 'scarlet' appears 1 times in the text file on the following lines: 1508 4 lab8_p1.py x lab8_p3.py x words5000.csv x scarlet.txt × lab8_p2.py × × 1 # Problem 2 2 word1 "red" 3 word2 = "scarlet" 5 # Add your code below 6 7 8 9 10 11 12 with open("scarlet.txt", "r") as file: for line in file: words line.strip().split(", ") word1_count= words.count(word1) word2_count= words.count(word2) print (f"The word '{word1}' appears: {word1_count} times") print(f"The word '{word2}' appears: (word2_count} times") CONSOLE SHELL Check Answer Reset to Template Recent Submissions
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education