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 to Expert-Tailored 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

Students also viewed these Databases questions

Question

What is the relation of physical mathematics with examples?

Answered: 1 week ago

Question

What are oxidation and reduction reactions? Explain with examples

Answered: 1 week ago