Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python code Have 'KJV.txt' loaded in the same folder with this jupyter notebook file. Then write a function that: Takes two words Print all lines
Python code
Have 'KJV.txt' loaded in the same folder with this jupyter notebook file. Then write a function that:
- Takes two words
- Print all lines that contains both words, in a case-insensitive way
- At the end, print the number of lines
And test the function with the following:
- 'good' and 'evil': 71 lines
- 'god' and 'love': 69 lines
- Your choice! Try any two words (not so simple ones)
my attempt
input
def wordCount(str1, str2): count = 0 for line in "KJV.txt": containsStr1 = False containsStr2 = False for word in line: if(word == str1): containsStr1 = True if(word == str2): containsStr2 = True if(containsStr1 == True and containsStr2 == True): count += 1 return count
print(wordCount("good", "evil"))
output
0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started