we'll collect some stats on a file of your choice. This file should be a plain-text file such as a previous assignment (a .py file) or anything else on your computer that ends with the .txt extension. As you read this file, display the each line to the screen with a line number At the end of your program, you display some statistics of the file which must include the Line Count and Character Count, feel free to add more. To calculate the Character Count, and Word Count DO NOT use any built-in functions to solve this for you such as len, split or regular expressions. For the purpose of this exercise, and as a challenge, try to solve this with a loop or other basic concept that we have learned about. Can you use a for loop to count characters from a string? Try it. Treat a string like it is a list of characters. There are different ways to read a file. One way reads everything as a string. Another reads lines, such that you'll have a list of strings. Try to open / read the entire file once. It's more efficient than reading the file 2 or 3 times. Don't forget to display the file with it's line number! You may use the .strip() function on a string. It will remove whitespace characters from the start and end of a string. sample pic attached
we'll collect some stats on a file of your choice. This file should be a plain-text file such as a previous assignment (a .py file) or anything else on your computer that ends with the .txt extension.
As you read this file, display the each line to the screen with a line number
At the end of your program, you display some statistics of the file which must include the Line Count and Character Count, feel free to add more. To calculate the Character Count, and Word Count DO NOT use any built-in functions to solve this for you such as len, split or regular expressions. For the purpose of this exercise, and as a challenge, try to solve this with a loop or other basic concept that we have learned about.
- Can you use a for loop to count characters from a string? Try it. Treat a string like it is a list of characters.
- There are different ways to read a file. One way reads everything as a string. Another reads lines, such that you'll have a list of strings.
- Try to open / read the entire file once. It's more efficient than reading the file 2 or 3 times.
- Don't forget to display the file with it's line number!
- You may use the .strip() function on a string. It will remove whitespace characters from the start and end of a string.
sample pic attached
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images