Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[Python] I need help with counting punctuation in a file in python. I have the following function: def remove_punc(s): result = for c in

[Python] I need help with counting punctuation in a file in python. I have the following function:

def remove_punc(s): result = \"\" for c in s: # If char is not punctuation, add it to the result. if c not in string.punctuation: result += c return result

#########################

and I have called it from main like this:

def main(): myFile = open(\"gameofthrones.txt\", \"r\") punctCount = 0 for line in myFile: print(remove_punc(line))

myFile.close()

if __name__ == '__main__': main()

##############################################

But now I have to count the amount of punctuation in the file, and I am not sure how to do that using the punctCount counter, any help is appreciated.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Cryptography And Network Security

Authors: William Stallings

5th Edition

B00F0ZR6PC, 9780136097044

Students also viewed these Programming questions