Question

Create a program that reads a text (.txt) file and does the following: a. Count the number of lines in the file b. Count the number of words in the file Create a sample text file with lines and words to test the program.

          Create a program that reads a text (.txt) file and does the following:
a. Count the number of lines in the file
b. Count the number of words in the file

Create a sample text file with lines and words to test the program.
        

Added by Paula B.

Computer Science and Information Technology
Computer Science and Information Technology
Trishna Knowledge Systems 2018 Edition
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
Create a program that reads a text (.txt) file and does the following: a. Count the number of lines in the file b. Count the number of words in the file Create a sample text file with lines and words to test the program.
Close icon
Play audio
Feedback
Powered by NumerAI
David Collins Jennifer Stoner
Kathleen Carty verified

Liam Haas-Neill and 89 other subject AP CS educators are ready to help you.

Ask a new question

*

Labs

-

Want to see this concept in action?

NEW

Explore this concept interactively to see how it behaves as you change inputs.

View Labs

*

Key Concepts

-
Key Concept
Premium Feature
Explore the core concept behind this problem.
Play button
Key Concept
Premium Feature
Explore the core concept behind this problem.
Your browser does not support the video tag.

*

Recommended Videos

-
write-a-complete-program-that-asks-the-user-to-enter-the-name-of-a-text-file-using-a-function-open-and-read-the-contents-of-the-file-and-count-how-many-lines-exist-in-the-text-file-display-o-69361

Write a complete program that asks the user to enter the name of a text file. Using a function, open and read the contents of the file and count how many lines exist in the text file. Display only the number of lines counted to the user. Do not display any message from the count_lines function. (Hint: ask yourself how lines are saved in a text file) Declare a function as below: int count_lines(string filename)

Liam H.

give-a-program-that-will-create-a-file-named-texttxt-and-write-ten-sentences-into-the-file-which-are-stored-as-one-sentence-per-line-give-a-function-that-reads-the-files-contents-and-calcula-86076

Give a program that will create a file named text.txt and write ten sentences into the file, which are stored as one sentence per line. Provide a function that reads the file's contents and calculates the average number of words per sentence.

Liam H.

count-consonants-and-vowels-write-a-program-that-prompts-the-user-to-enter-a-text-filename-and-displ

(Count consonants and vowels) Write a program that prompts the user to enter a text filename and displays the number of vowels and consonants in the file. Use a set to store the vowels A, E, I, O, and U.

Introduction to Programming Using Python


*

Recommended Textbooks

-
Computer Science and Information Technology

Computer Science and Information Technology

Trishna Knowledge Systems 2018 Edition
achievement 1,962 solutions
Introduction to Programming Using Python

Introduction to Programming Using Python

Y. Daniel Liang 1st Edition
achievement 1,275 solutions
Computer Science - An Overview

Computer Science - An Overview

Glenn Brookshear, Dennis Brylow 12th Edition
achievement 1,350 solutions

*

Transcript

-
00:01 Okay, this one says, a complete program that asks the user to enter the name of a text file.
00:06 Using a function, open and read the content of the file, count how many lines exist in the file.
00:12 Play only the number of lines counted to the user do not display any message from the count lines function.
00:21 I'm not familiar with that function, so i guess that's fine.
00:27 Clear a function.
00:28 Oh, i guess that's our function.
00:30 Okay.
00:31 So they want us to make a function, and we're going to call it a function.
00:33 Count lines.
00:36 It's going to take string, file name.
00:42 But since this is python, we don't need to say string, actually.
00:45 So we're just going to do that.
00:46 And we're going to say f equals open.
00:50 Looks like we have a file called text of txc.
00:53 And we're going to say f.
00:55 Read.
00:57 And we're going to say for, we're going to say text equals f .reed...
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Join the community

18,000,000+

Students on Numerade


Trusted by students at 8,000+ universities

Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever