Reference no: EM132103985
Problem
In Python, write a function called countLines() that takes a string representing the name of a file as a parameter, and a string representing a word as the second parameter.
The function should go line by line through the file and count the number of lines that contain the word. It should then return that value.
For example, if you are searching through 'example.txt' which contains the following:
Here is a random file...
This is the second line.
There is a blank line above this line.
Then countLines('example.txt', 'is') would return 3.
countLines('example.txt','line') would return 2.
Note that the string 'line' is present once in line 2, and twice in line 4. However, we are only counting the lines that contain this string.
Hint: Look up the function 'find()' in the string class. What does it return if a string is NOT found?
Your program should use exception handling to look for either an IOError or a FileNotFoundError when the opening the input file. If the program can't open the file, print a line that says: 'Unable to open file'. Then end the function using the 'return' statement. (Do not return any value).
What diameter will you choose for your wire
: You're given of copper and asked to make a wire, using all the metal, with a resistance of. Copper has a density of 8900 kg/m3.
|
How do you find the angle of incidence
: How do you find the angle of incidence in this problem, I am having trouble solving this.
|
Implementation of two algorithms-merge sort and binary
: Implementation of any two algorithms from the following algorithms: Merge Sort, Quicksort, Binary Search, Euclidean Algorithm(for Önding gcd).
|
Determine its minimum point using the matlab routine
: Determine its minimum point using the Matlab routine ‘fminsearch'.
|
Write a function called countlines that takes a string
: Write a function called countLines() that takes a string representing the name of a file as a parameter, & a string representing a word as the second parameter.
|
Find the primes p and q
: Find the primes p and q. Find the decoding key, d, using the Euclidean Algorithm. Encode "Eleven" with the public key.
|
How do you find the average spacing between atoms
: How do you find the average spacing between atoms in the crystal for this problem, I am having trouble.
|
How would you determine an appropriate value for threshold
: Your boss asks you to determine the number of erroneous login attempts that should be allowed before a user's account is locked.
|
Write the five queue operations for this implementation
: Write the five queue operations for this implementation.Compare this implementation with the circular queue implementation discussed in class.
|