Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you change this Python code to A C program with the same output as the Python Code import string print(r'C:meshesas') filename = r'C:example.txt' #

Can you change this Python code to A C program with the same output as the Python Code

import string

print(r'C:\meshes\as') filename = r'C:\example.txt' # Open the file in read mode #text = open("C:\Users\GojiraMini\source\ epos\My_Short_Story_Counter\My_Short_Story_Counter\short_story.txt", "r") text = open(filename, 'r') # Create an empty dictionary d = dict() # Loop through each line of the file for line in text: # Remove the leading spaces and newline character line = line.strip() # Convert the characters in line to # lowercase to avoid case mismatch line = line.lower() # Remove the punctuation marks from the line line = line.translate(line.maketrans("", "", string.punctuation)) # Split the line into words words = line.split(" ") # Iterate over each word in line for word in words: # Check if the word is already in dictionary if word in d: # Increment count of word by 1 d[word] = d[word] + 1 else: # Add the word to dictionary with count 1 d[word] = 1 # Print the contents of dictionary i = 1 for key in list(d.keys()): if i % 23 == 0: i = 1 input("Press a button to continue") # For Python 3 raw_input("Press a button to continue") # For Python 2 i = i + 1 print(key, ":", d[key])

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

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions