1. Create a function called character_count(). This function takes a filename as a parameter, and it...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Create a function called character_count(). This function takes a filename as a parameter, and it should return the number of characters (.e., letters) in the file. This function is basically the same as one of the functions (word_count()) that the TA will show in the demonstration. In this function, you'll have to have an embedded loop to count the characters in each word. The function should not count the newline character. When you call this function using words.txt as input, you should receive a character count of 982 728. If you got 1 816 518, you haven't removed the newline (\n) character properly. Hint: You can use the string method, strip(), that your TA showed you in the demo, and which can be found in Chapter 9.1 of the textbook. Alternatively, you can check for the string "\n" and not count it; it's up to you. 2. Next, create a function called find_word (). This function takes two parameters: a filename and a number. When you call find word() with a number n, it will return the nth word in the file. For example, when called using the number 10, find word() will return aardvark. For this function, you want to keep track of which word you are at with some sort of count variable. When the count matches the number parameter, then you have arrived at the word you're looking for, so just close the file and return that word. 3. Finally, create a main() function that allows users to get the character count for a filename that they pass to it. (This means that the user will input the filename-it shouldn't be hardcoded.) Next, prompt the user for the index number they want to check for a word. Make sure that the result of each function is printed nicely using f-strings. Finally, check if the user wants to enter another index so that they can find another word. If they do, loop. If they don't, end the program. Hint: use a while loop to keep the loop running, and then use N as your sentinel value. 1. Create a function called character_count(). This function takes a filename as a parameter, and it should return the number of characters (.e., letters) in the file. This function is basically the same as one of the functions (word_count()) that the TA will show in the demonstration. In this function, you'll have to have an embedded loop to count the characters in each word. The function should not count the newline character. When you call this function using words.txt as input, you should receive a character count of 982 728. If you got 1 816 518, you haven't removed the newline (\n) character properly. Hint: You can use the string method, strip(), that your TA showed you in the demo, and which can be found in Chapter 9.1 of the textbook. Alternatively, you can check for the string "\n" and not count it; it's up to you. 2. Next, create a function called find_word (). This function takes two parameters: a filename and a number. When you call find word() with a number n, it will return the nth word in the file. For example, when called using the number 10, find word() will return aardvark. For this function, you want to keep track of which word you are at with some sort of count variable. When the count matches the number parameter, then you have arrived at the word you're looking for, so just close the file and return that word. 3. Finally, create a main() function that allows users to get the character count for a filename that they pass to it. (This means that the user will input the filename-it shouldn't be hardcoded.) Next, prompt the user for the index number they want to check for a word. Make sure that the result of each function is printed nicely using f-strings. Finally, check if the user wants to enter another index so that they can find another word. If they do, loop. If they don't, end the program. Hint: use a while loop to keep the loop running, and then use N as your sentinel value.
Expert Answer:
Answer rating: 100% (QA)
Heres a Python program that implements the three functions you described def chara... View the full answer
Related Book For
Numerical Methods With Chemical Engineering Applications
ISBN: 9781107135116
1st Edition
Authors: Kevin D. Dorfman, Prodromos Daoutidis
Posted Date:
Students also viewed these programming questions
-
On July 31, 2013, Cooks Castle Resorts issues a $2,500,000, 10 year, 6.5% Bond with interest payable semiannually on January 31 and July 31 of each of the next ten years. The market interest rate on...
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
SummaryOnline BookwormsA preview of the page you will create is shown below.Instructions ?|Daniel Palmer is a content manager of Online Bookworms, a website dedicated to lovers of books and reading....
-
The value of a dirt bike decreases by 25% each year. If you purchased this dirt bike today for $500, to the nearest dollar how much would the bike be worth 5 years later?
-
In a 100-unit apartment building, when the price charged per apartment rental is (830 + 30x) dollars, then the number of apartments rented is 100 - x and the total revenue for the building is R(x) =...
-
The demand curve for a product is given by where Pz = $ 300. a. What is the own price elasticity of demand when Px = $ 140? Is demand elastic or inelastic at this price? What would happen to the...
-
You were engaged to examine the financial statements of Ronlyn Corporation for the year ended June 30. On May 1, the Co poration borrowed \(\$ 500,000\) from Second National Bank to finance plant...
-
Fenwicke Company began operating a subsidiary in a foreign country on January 1, 2011, by acquiring all of its common stock for LCU 40,000, which was equal to fair value. This subsidiary immediately...
-
How does capitalism fit in with modern business life and how does it impact ethical dilemmas that you have seen or heard of in the workplace? What are two of the most interesting historical ethical...
-
A project has a first cost of \($180,000,\) an estimated salvage value of \($20,000\) after 6 years, and other economic attributes as detailed in the table below. Unfortunately, as the end of year 4...
-
Given the following matrix comprising of a vector of reaction coefficients, vector of endogenous variables and a vector of constants and exogenous variables, Ly L, 1-c,(1-T)-1, (C,+1)] [?c, +?l, +?G,...
-
Explain the working principle of a gas turbine on closed cycle.
-
Discuss the classification of turbines. Also, discuss compounding of impulse turbine.
-
What are the advantages of the steam turbine over reciprocating engines?
-
List any four differences between closed cycle and open cycle gas turbines.
-
Derive the equation for thermal efficiency of Rankine cycle.
-
1. Consider an impulse response h[n] such that h[n] = 0 for n < 0 and n > M, and h[n] = -h[M-n] for 0 n M where M is an odd integer. a) Express the Fourier transform of h[n] in the form H(jw) =...
-
Define cultural intelligence. Cite the books or journal articles you found in Capella's library. Explain why cultural intelligence is important for HR practitioners and other organizational managers.
-
How do the location and classifications of the steady states for the system change if the second equation becomes [x2] = [ d dt X2 x + x2 x1 + x2
-
Use Picards method to find a root of the system of equations using the initial guesses x (0) 1 = 0 and x (0) 2 = 0. f(x, x) = ex1 - x2 f2(x, x) = x + x 3x2 - (3.7.6) (3.7.7)
-
Write a program to solve using implicit Euler. dy dt = y/2, y(0) = 2 (4.2.39)
-
On 1 June, Sugar Rush Ltd had Accounts Receivable and Allowance for Doubtful Debts accounts as below. GST Inclusive. The following transactions occurred during the month of June: 5. Credit sales...
-
On 1 June, Cambria Financial Services Ltd had balances in the Accounts Receivable and Allowance for Doubtful Debts accounts as set out below. Ignore GST. The following transactions occurred during...
-
Outback Get Away Ltd sells four-wheel drive accessories and recovery equipment on credit. The accounting records at 30 June 2023 highlights the following. Ignore GST. In the past, the companys yearly...
Study smarter with the SolutionInn App