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
![C. Command Prompt
116 # print the car model per make
117 model = model_dict[nation] [make]
118
119
len (model)
120
121
print
122 print
123
124
for i in range (L):
125
if (i < L-1):
126 print model[i] +
127 else:
128 print model [i]
129-
130 print
131 see_model = raw_input('
132
print
133 -
134 # prompt to see if user wants to look up cars again
135 look_up_car = raw_input(' Do you want to look up car again (Y/N)?: ')
136
print
137-
138
print '-'*46
139
print('THANK YOU FOR USING OUR SERVICES. COME BACK SOON!')
140 print '=' *46
–
L =
=
+make+
Line Count: 140
Character Count: 4899
# how many models per car make
models:',
Additional %s car models (Y/N)?:
%country)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7b09c4c0-6ff8-4fb0-8686-5831a4a6c832%2F382eae7f-af19-4edb-8219-23cfca14aedb%2Fbo2n1u_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









