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.
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3200e892-7b83-4670-8aa5-c4c84f2a6adb%2Ffb89d20c-4888-4574-84b8-621f73c4fde4%2Fl6sojng_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









