1f) Percent Difficult Words Using dale_chall_words, define a function percent_difficult_words that given a text input will calculate the percent difficult words, using the following approach: Return the percent of words in a given text input that are not in dale_chal1_words['easy_words'] . Note that a "word" is defined by being separated from other text by a space.

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
icon
Concept explainers
Question

Using Python

Where am I going wrong with my code that the the "Difficult words percentage is :" keeps returning 100% instead of the correct percentage for the input text?

In [14]:
N # YOUR CODE HERE
dale_chall_file = pd.read_csv('data/dale_chall.txt', names =
['easy_words'])
In [15]:
I dale_chall_file
Out[15]:
easy_words
a
1
able
2
abler
3
ablest
4
abling
...
8485
yourself
8486
yourselves
8487
yous
8488
youth
8489
youths
8490 rows x 1 columns
In [16]:
I assert dale_chall_file.shape == (8490, 1)
assert list(dale_chall_file.columns) ==
['easy_words']
1f) Percent Difficult Words
Using dale_chall_words, define a function percent_difficult_words that given a text input will calculate the percent difficult words, using the following
approach: Return the percent of words in a given text input that are not in dale_chall_words['easy_words']
Note that a "word" is defined by being separated from other text by a space.
In [18]:
I # YOUR CODE HERE
def percent_difficult_words (dale_chall_file):
text_input = input("Please Enter a text : ")
text_input_words = text_input.split()
difficult_words_count = e
for i in text_input_words:
if i not in dale_chall_file:
difficult_words_count += 1
return difficult_words_count / len(text_input_words)
final_percent_difficult_words = percent_difficult_words (dale_chall_file) * 100
print("Difficult words percentage is : ", final_percent_difficult_words, "%")
Please Enter a text : i am testing a program
Difficult words percentage is :
100.0 %
In [ ]:
I assert callable(percent_difficult_words)
assert percent_difficult_words ("there are only easy words here") == 0
assert percent_difficult_words("let us put one difficult word here") == 1/7
assert percent_difficult_words("thare aree noo unintentional misstakes")
== 1
Transcribed Image Text:In [14]: N # YOUR CODE HERE dale_chall_file = pd.read_csv('data/dale_chall.txt', names = ['easy_words']) In [15]: I dale_chall_file Out[15]: easy_words a 1 able 2 abler 3 ablest 4 abling ... 8485 yourself 8486 yourselves 8487 yous 8488 youth 8489 youths 8490 rows x 1 columns In [16]: I assert dale_chall_file.shape == (8490, 1) assert list(dale_chall_file.columns) == ['easy_words'] 1f) Percent Difficult Words Using dale_chall_words, define a function percent_difficult_words that given a text input will calculate the percent difficult words, using the following approach: Return the percent of words in a given text input that are not in dale_chall_words['easy_words'] Note that a "word" is defined by being separated from other text by a space. In [18]: I # YOUR CODE HERE def percent_difficult_words (dale_chall_file): text_input = input("Please Enter a text : ") text_input_words = text_input.split() difficult_words_count = e for i in text_input_words: if i not in dale_chall_file: difficult_words_count += 1 return difficult_words_count / len(text_input_words) final_percent_difficult_words = percent_difficult_words (dale_chall_file) * 100 print("Difficult words percentage is : ", final_percent_difficult_words, "%") Please Enter a text : i am testing a program Difficult words percentage is : 100.0 % In [ ]: I assert callable(percent_difficult_words) assert percent_difficult_words ("there are only easy words here") == 0 assert percent_difficult_words("let us put one difficult word here") == 1/7 assert percent_difficult_words("thare aree noo unintentional misstakes") == 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
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