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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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)
Transcribed Image Text: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)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education