Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A. Counting Keywords Write a Python program that will read any Python source program file and print out a frequency count of the reserved words
A. Counting Keywords Write a Python program that will read any Python source program file and print out a frequency count of the reserved words in the file. You can find a list of the Python keywords on the Python.org website: docs.python.org/3/reference/1exical-analysis.html#keywords Your program should print each keyword and its associated count, one per line, in alphabetic order. Do not list keywords that appear zero times in the file. Do not import or use any Python modules in your program. Your program should do the following: 'Prompt the user and input the name of a Python source code file (.py) * Read the contents of the file and construct a dictionary consisting of the keywords and their associated counts *Print a list of all keywords and their associated counts in alphabetic order of keywords (include only those with non-zero counts) Example: Enter the filename: junk2.py Keyword frequency in alphabetic order: def for if in return 3 6 A. Counting Keywords Write a Python program that will read any Python source program file and print out a frequency count of the reserved words in the file. You can find a list of the Python keywords on the Python.org website: docs.python.org/3/reference/1exical-analysis.html#keywords Your program should print each keyword and its associated count, one per line, in alphabetic order. Do not list keywords that appear zero times in the file. Do not import or use any Python modules in your program. Your program should do the following: 'Prompt the user and input the name of a Python source code file (.py) * Read the contents of the file and construct a dictionary consisting of the keywords and their associated counts *Print a list of all keywords and their associated counts in alphabetic order of keywords (include only those with non-zero counts) Example: Enter the filename: junk2.py Keyword frequency in alphabetic order: def for if in return 3 6
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started