Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 5, Problem 14PE
Program Plan Intro
Program to print the count of lines,words and characters
Program plan
- Inside the “main()” function,
- Declare variables “filename” and “filedata” and get input from user.
- Print lines, words and characters.
- Call the function “main()”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Must be written in Python.
OWrite a program that reads data from a file containing integers that ends with -999.
Output the numbers that are divisible by 7
Output the numbers that are divisible by 11
Output the numbers that are not divisible by 7 or 11.
A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a file. The program should output the unique words and their frequencies in alphabetical order. Variations are to track sequences of two words and their frequencies, or n words and their frequencies.
Below is an example file along with the program input and output:
example.txt
I AM SAM I AM SAM SAM I AM
Chapter 5 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 5 - Prob. 1TFCh. 5 - Prob. 2TFCh. 5 - Prob. 3TFCh. 5 - Prob. 4TFCh. 5 - Prob. 5TFCh. 5 - Prob. 6TFCh. 5 - Prob. 7TFCh. 5 - Prob. 8TFCh. 5 - Prob. 9TFCh. 5 - Prob. 10TF
Ch. 5 - Prob. 1MCCh. 5 - Prob. 2MCCh. 5 - Prob. 3MCCh. 5 - Prob. 4MCCh. 5 - Prob. 5MCCh. 5 - Prob. 6MCCh. 5 - Prob. 7MCCh. 5 - Prob. 8MCCh. 5 - Prob. 9MCCh. 5 - Prob. 10MCCh. 5 - Prob. 1DCh. 5 - Prob. 2DCh. 5 - Prob. 3DCh. 5 - Prob. 4DCh. 5 - Prob. 5DCh. 5 - Prob. 1PECh. 5 - Prob. 2PECh. 5 - Prob. 3PECh. 5 - Prob. 4PECh. 5 - Prob. 5PECh. 5 - Prob. 6PECh. 5 - Prob. 7PECh. 5 - Prob. 8PECh. 5 - Prob. 9PECh. 5 - Prob. 10PECh. 5 - Prob. 11PECh. 5 - Prob. 12PECh. 5 - Prob. 13PECh. 5 - Prob. 14PECh. 5 - Prob. 15PECh. 5 - Prob. 16PE
Knowledge Booster
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.Similar questions
- IN JAVA Arrange the data for your chart in a text file as follows: The first line of the file is the title for the chart The second line of the file is the units used in the chart The rest of the file contains data values for the chart alternating with the label to print with the value on the preceding line. The program must be able to produce a chart from any data file arranged as described above. The name of the data file and the output file are provided on the command line. The program must check that there are enough command line arguments and stop with a suitable message if not. The program saves the chart to the output file (2nd command line argument); it may also display the chart to the terminal, but it is not required to. In addition to the above, accept two additional command line arguments: The maximum width for the chart (just the bar itself, not including the labels) The symbol to use for the barsarrow_forwardwordCountDistinct.py: Write a program that reads words from a file (filename given as a command-line argument) and prints the number of distinct words. Words that differ only in case should be considered to be equivalent.For example, using the input: If there's a problem yo I'll solve itCheck out the hook while my DJ revolves itIce ice baby The program should print 18.arrow_forwardIn Python Write a program that consists of (at least) two function: A function that creates and saves data in a file. The saved data represents exam grades. In the function, you will create n random numbers in the range [0,100], where n is the number of students. The function can be called as follows: createFile(filename, n) Main function, in which the user inputs the file name and the number of students, then the main calls function createFile. The main should perform validation for n (should be > 0), and the filename (should end with .txt). I will explain how to validate strings in the coming lecture. Hint: a good developer will write four functions to solve the problem.arrow_forward
- PYTHON CODINGarrow_forwardWrite a Program in CWrite a c program that counts the number of words and characters in a file. The program should do the following: Asks the user to input the name of the file to be opened. Display the contents of the file. Counts and displays the number of words and characters in a file. Exclude the spaces in the character count. Create a new file named “<inputted_file_name>_wordcharct.txt”, e.g. if the file name inputted in part a is “test.txt” then the file created should be named “test_wordcharct.txt”. Store the displayed information in this file Expected output: Sample 1: Input the file name to be opened: test.txtThe content of the file “test.txt” are: test line 1 test line 2 test line 3 test line 4 -----End of File---- The number of words in the file “test.txt” are: 12 The number of characters in the file “test.txt” are: 36The file “test_wordcharct.txt” containing the results was created successfully! Sample 2: (use this one in creating the program) Input the file…arrow_forwardIN PYTHON LANGUAGEarrow_forward
- wordCount.py: Write a program that reads words from a file (filename given as a command-line argument) and prints the number of words.For example using an input: If there's a problem yo I'll solve itCheck out the hook while my DJ revolves itIce ice baby The program should print 20.arrow_forwardComputer Science C++ Create a text file "input.txt" with a certain amount of integers (you decide how many). Write a program that reads these numbers from the file, adds them, and when you have reached the end of the file, calculates the average of these numbers. Print a message and the average to the console. Code this program twice, demonstrating the two methods to detect the end of the file, part A: reading a value from Instream and storing it (boolean expression) in the while loop part B: using the eof() member functionarrow_forwardIn Python plEASE The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header. Each line should contain: An employee's name The hours worked The wages paid for that period. An example of the program input and output is shown below: Enter the file name: data.txt Name Hours Total Pay Lambert 34 357.00 Osborne 22 137.50 Giacometti 5 503.50arrow_forward
- Please in C Language Write a program that uses an existing text file (text.txt) to determine the number of occurrences of each letter. You can assume that the file is filled with only lowercase letters and only the letters from a-z are present! Write the result in a new file to be created by the program! Errors when opening and closing the files must be caught Data.txt I love my moneyarrow_forwardJAVA PPROGRAM Write a program that prompts the user to enter a file name, then opens the file in text mode and reads names. The file contains one name on each line. The program then compares each name with the name that is at the end of the file in a symmetrical position. For example if the file contains 10 names, the name #1 is compared with name #10, name #2 is compared with name #9, and so on. If you find matches you should print the name and the line numbers where the match was found. While entering the file name, the program should allow the user to type quit to exit the program. If the file with a given name does not exist, then display a message and allow the user to re-enter the file name. The file may contain up to 100 names. You can use an array or ArrayList object of your choosing, however you can only have one array or ArrayList. Input validation: a) If the file does not exist, then you should display a message "File 'somefile.txt' is not found." and allow the…arrow_forwardWrite a program that asks the user for the name of a file. The program should display onlythe first five lines of the file’s contents. If the file contains less than five lines, it shoulddisplay the file’s entire contents. Pythonarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning